Skip to content

Commit 7d36118

Browse files
committed
fetch if needed
1 parent 24a2f3e commit 7d36118

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

@types/paper-graph.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ type Paper = {
1111
title: string,
1212
year: number,
1313
authors: _Author[],
14-
abstract: string | null
14+
abstract?: string | null
1515

1616
referenceCount: number,
1717
citationCount: number,
1818

1919
references: RelatedPaper[] | null,
2020
citations: RelatedPaper[] | null,
21-
referenceScids: string[],
22-
citationScids: string[],
21+
22+
referenceScids?: string[],
23+
citationScids?: string[],
2324

2425
relatedPapers: { references: RelatedPaper[], citations: RelatedPaper[] },
2526
}

app/tools/paper-graph/Search.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
fetchFromSemanticScholar,
77
addToNotionDatabase,
88
updateNotionPage,
9+
fetchNotionBlock,
910
} from './utils';
1011
import { SearchIcon } from '@public/icons';
1112
import { Loading } from '@components/atoms';
@@ -73,15 +74,22 @@ export default function Search({
7374
const referencesScidSet = new Set(paper.references?.map(ref => ref.scid))
7475
const citationsScidSet = new Set(paper.citations?.map(ref => ref.scid))
7576
for (const notionPaper of knownPapers) {
77+
if (notionPaper.citationScids === undefined || notionPaper.referenceScids === undefined) {
78+
const fetchedPaper = await fetchNotionBlock(notionPaper.id)
79+
notionPaper.abstract = fetchedPaper.abstract
80+
notionPaper.citationScids = fetchedPaper.citationScids
81+
notionPaper.referenceScids = fetchedPaper.referenceScids
82+
}
83+
7684
if (referencesScidSet.has(notionPaper.scid)
77-
|| notionPaper.citationScids.includes(paper.scid)) {
85+
|| notionPaper.citationScids?.includes(paper.scid)) {
7886
await updateNotionPage(notionPaper.id, {
7987
citations: [...(notionPaper.citations ?? []), { id: returnedPaper.id }],
8088
})
8189
returnedPaper.references?.push({ id: notionPaper.id } as any)
8290
}
8391
if (citationsScidSet.has(notionPaper.scid)
84-
|| notionPaper.referenceScids.includes(paper.scid)) {
92+
|| notionPaper.referenceScids?.includes(paper.scid)) {
8593
await updateNotionPage(notionPaper.id, {
8694
references: [...(notionPaper.references ?? []), { id: returnedPaper.id }],
8795
})

0 commit comments

Comments
 (0)