From c6d4d93c5d66db4b634dbc7d678bed1b2680ea65 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:16:15 +0100 Subject: [PATCH] fix: note link section count exclude invalid items --- src/modules/workspace/link.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/workspace/link.ts b/src/modules/workspace/link.ts index 76f370c..cc784a6 100644 --- a/src/modules/workspace/link.ts +++ b/src/modules/workspace/link.ts @@ -98,6 +98,7 @@ async function renderSection( outbound: addon.api.relation.getNoteLinkOutboundRelation, }; const inLinks = await api[type](item.id); + let count = 0; for (const linkData of inLinks) { const targetItem = (await Zotero.Items.getByLibraryAndKeyAsync( linkData[ @@ -108,7 +109,12 @@ async function renderSection( linkData[ { inbound: "fromKey", outbound: "toKey" }[type] as "fromKey" | "toKey" ], - )) as Zotero.Item; + )) as Zotero.Item | false; + + if (!targetItem) { + continue; + } + count ++; const linkParams = { workspaceUID: (body.closest("bn-workspace") as Workspace)?.dataset.uid, @@ -160,7 +166,6 @@ async function renderSection( body.append(row); } - const count = inLinks.length; setCount(count); }