fix: note link section count exclude invalid items

This commit is contained in:
windingwind 2024-12-13 12:16:15 +01:00
parent a667f8ac72
commit c6d4d93c5d

View File

@ -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);
}