Skip to content

Commit fa9c628

Browse files
committed
fix: avoid pushing undefined to blocks array in service
1 parent 919bac3 commit fa9c628

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

projects/ngx-notion-cms/src/lib/components/database-item/database-item.component.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ export class DatabaseItemComponent implements OnInit {
4747
if (response.data) {
4848
const blocks = response.data;
4949
blocks.forEach(block => {
50-
if (block.type === 'page') {
51-
this.imgSrc.set(getBlockImageURL(block.format!.page_cover!, block!))
52-
50+
if (block?.type === 'page' && block.format?.page_cover) {
51+
this.imgSrc.set(getBlockImageURL(block.format.page_cover!, block!))
5352
}
5453
})
5554
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
@let notionBlock = notionBlockSignal();
22

3-
<div class="flex flex-col gap-3 w-full">
4-
@defer {
5-
<div class="h-[160px] w-full relative">
6-
<img
7-
fill
8-
class="object-cover rounded-3xl"
9-
title="page_cover"
10-
priority
11-
[ngSrc]="imgSrc()" />
12-
</div>
13-
} @placeholder {
14-
<div class="h-40 w-full bg-slate-100 rounded-3xl"></div>
15-
}
3+
@if (notionBlock) {
4+
<div class="flex flex-col gap-3 w-full">
5+
@if (imgSrc()) {
6+
@defer {
7+
<div class="h-[160px] w-full relative">
8+
<img
9+
fill
10+
class="object-cover rounded-3xl"
11+
title="page_cover"
12+
priority
13+
[ngSrc]="imgSrc()" />
14+
</div>
15+
} @placeholder {
16+
<div class="h-40 w-full bg-slate-100 rounded-3xl"></div>
17+
}
18+
}
1619

17-
<h1 class="text-3xl font-bold mb-5">
18-
{{ (notionBlock.properties?.title)![0][0] }}
19-
</h1>
20-
</div>
20+
<h1 class="text-3xl font-bold mb-5">
21+
{{ (notionBlock.properties?.title)![0][0] }}
22+
</h1>
23+
</div>
24+
}

projects/ngx-notion-cms/src/lib/components/page-cover/page-cover.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { NgOptimizedImage } from '@angular/common'
1818
export class PageCoverComponent {
1919
notionBlockSignal = input.required<NotionBlock>({ 'alias': 'notionBlock' })
2020
imgSrc = computed(() => {
21-
if (this.notionBlockSignal().format?.page_cover) {
21+
if (this.notionBlockSignal().type && this.notionBlockSignal()?.format?.page_cover) {
2222
return getBlockImageURL(this.notionBlockSignal().format!.page_cover!, this.notionBlockSignal()!)
2323
}
2424
return ''

projects/ngx-notion-cms/src/lib/services/notion.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export class NgxNotionService {
2424
if (response.data) {
2525
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2626
Object.values(response.data).forEach((key: any) => {
27-
blocks.push(key.value);
27+
if (key.value) {
28+
blocks.push(key.value);
29+
}
2830
});
2931
return {
3032
data: blocks,

projects/ngx-notion-testbed-app/src/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<base href="/" />
77
<meta name="viewport" content="width=device-width, initial-scale=1" />
88
<link rel="icon" type="image/x-icon" href="image.ico" />
9+
<link rel="preconnect" href="https://www.notion.so" />
910
</head>
1011
<body>
1112
<app-root></app-root>

0 commit comments

Comments
 (0)