A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix: Improve field names in the tag APIs
Mohamed Bassem4086c37b830c
diff --git a/apps/cli/src/commands/tags.ts b/apps/cli/src/commands/tags.tsindex c2c1dd3a..14cb7f10 100644--- a/apps/cli/src/commands/tags.ts+++ b/apps/cli/src/commands/tags.ts@@ -21,14 +21,14 @@ tagsCmdtry {const tags = (await api.tags.list.query()).tags;- tags.sort((a, b) => b.count - a.count);+ tags.sort((a, b) => b.numBookmarks - a.numBookmarks);if (getGlobalOptions().json) {printObject(tags);} else {const data: string[][] = [["Id", "Name", "Num bookmarks"]];tags.forEach((tag) => {- data.push([tag.id, tag.name, tag.count.toString()]);+ data.push([tag.id, tag.name, tag.numBookmarks.toString()]);});console.log(table(data, {diff --git a/apps/web/components/dashboard/tags/AllTagsView.tsx b/apps/web/components/dashboard/tags/AllTagsView.tsxindex f6a42ef2..72f4dc11 100644--- a/apps/web/components/dashboard/tags/AllTagsView.tsx+++ b/apps/web/components/dashboard/tags/AllTagsView.tsx@@ -59,10 +59,10 @@ function DeleteAllUnusedTags({ numUnusedTags }: { numUnusedTags: number }) {const byUsageSorter = (a: ZGetTagResponse, b: ZGetTagResponse) => {// Sort by name if the usage is the same to get a stable result- if (b.count == a.count) {+ if (b.numBookmarks == a.numBookmarks) {return byNameSorter(a, b);}- return b.count - a.count;+ return b.numBookmarks - a.numBookmarks;};const byNameSorter = (a: ZGetTagResponse, b: ZGetTagResponse) =>a.name.localeCompare(b.name, undefined, { sensitivity: "base" });@@ -102,9 +102,13 @@ export default function AllTagsView({// Sort tags by usage descconst allTags = data.tags.sort(sortByName ? byNameSorter : byUsageSorter);- const humanTags = allTags.filter((t) => (t.countAttachedBy.human ?? 0) > 0);- const aiTags = allTags.filter((t) => (t.countAttachedBy.ai ?? 0) > 0);- const emptyTags = allTags.filter((t) => t.count === 0);+ const humanTags = allTags.filter(+ (t) => (t.numBookmarksByAttachedType.human ?? 0) > 0,+ );+ const aiTags = allTags.filter(+ (t) => (t.numBookmarksByAttachedType.ai ?? 0) > 0,+ );+ const emptyTags = allTags.filter((t) => t.numBookmarks === 0);const tagsToPill = (tags: typeof allTags) => {let tagPill;@@ -116,7 +120,7 @@ export default function AllTagsView({key={t.id}id={t.id}name={t.name}- count={t.count}+ count={t.numBookmarks}isDraggable={draggingEnabled}onOpenDialog={handleOpenDialog}/>diff --git a/packages/shared/types/tags.ts b/packages/shared/types/tags.tsindex 7828c645..54dc3eb5 100644--- a/packages/shared/types/tags.ts+++ b/packages/shared/types/tags.ts@@ -12,8 +12,8 @@ export type ZBookmarkTags = z.infer<typeof zBookmarkTagSchema>;export const zGetTagResponseSchema = z.object({id: z.string(),name: z.string(),- count: z.number(),- countAttachedBy: z.record(zAttachedByEnumSchema, z.number()),+ numBookmarks: z.number(),+ numBookmarksByAttachedType: z.record(zAttachedByEnumSchema, z.number()),});export type ZGetTagResponse = z.infer<typeof zGetTagResponseSchema>;diff --git a/packages/trpc/routers/tags.ts b/packages/trpc/routers/tags.tsindex c04593c9..c080bad8 100644--- a/packages/trpc/routers/tags.ts+++ b/packages/trpc/routers/tags.ts@@ -80,7 +80,9 @@ export const tagsAppRouter = router({throw new TRPCError({ code: "NOT_FOUND" });}- const countAttachedBy = res.reduce<Record<ZAttachedByEnum, number>>(+ const numBookmarksByAttachedType = res.reduce<+ Record<ZAttachedByEnum, number>+ >((acc, curr) => {if (curr.attachedBy) {acc[curr.attachedBy]++;@@ -93,8 +95,11 @@ export const tagsAppRouter = router({return {id: res[0].id,name: res[0].name,- count: Object.values(countAttachedBy).reduce((s, a) => s + a, 0),- countAttachedBy,+ numBookmarks: Object.values(numBookmarksByAttachedType).reduce(+ (s, a) => s + a,+ 0,+ ),+ numBookmarksByAttachedType,};}),delete: authedProcedure@@ -343,8 +348,8 @@ export const tagsAppRouter = router({const resp = tags.map(({ tagsOnBookmarks, ...rest }) => ({...rest,- count: tagsOnBookmarks.length,- countAttachedBy: tagsOnBookmarks.reduce<+ numBookmarks: tagsOnBookmarks.length,+ numBookmarksByAttachedType: tagsOnBookmarks.reduce<Record<ZAttachedByEnum, number>>((acc, curr) => {