Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

Sub-collections included in link count on tree

Katie Bohnenkamper5a5fa9ed6cbf
diff --git a/components/CollectionListing.tsx b/components/CollectionListing.tsx
index f218b462..841ab0e3 100644
--- a/components/CollectionListing.tsx
+++ b/components/CollectionListing.tsx
@@ -327,6 +327,23 @@ const buildTreeFromCollections = (
});
}
+ function getTotalLinkCount(collectionId: number): number {
+ const collection = items[collectionId];
+ if (!collection) {
+ return 0;
+ }
+
+ let totalLinkCount = collection.data._count?.links || 0;
+
+ if (collection.hasChildren) {
+ collection.children.forEach((childId) => {
+ totalLinkCount += getTotalLinkCount(childId as number);
+ });
+ }
+
+ return totalLinkCount;
+ }
+
const items: { [key: string]: ExtendedTreeItem } = collections.reduce(
(acc: any, collection) => {
acc[collection.id as number] = {
@@ -380,6 +397,14 @@ const buildTreeFromCollections = (
}
});
+ collections.forEach((collection) => {
+ const collectionId = collection.id;
+ if (items[collectionId as number] && collection.id) {
+ const linkCount = getTotalLinkCount(collectionId as number);
+ items[collectionId as number].data._count.links = linkCount;
+ }
+ });
+
const rootId = "root";
items[rootId] = {
id: rootId,