diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-15 13:32:05 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-15 13:32:05 +0000 |
| commit | a9e4ec0922b5da71aaae7f6a037f124c86b38edc (patch) | |
| tree | 67d3470ef6ef2f7bbd6971614251697b10c172a1 /apps | |
| parent | aa8df79ab48c2e2d9f8b10fbdf4d71197f41303e (diff) | |
| download | karakeep-a9e4ec0922b5da71aaae7f6a037f124c86b38edc.tar.zst | |
refactor: Move tag fetching to trpc to reuse in the mobile app
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/web/app/dashboard/tags/[tagName]/page.tsx | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/apps/web/app/dashboard/tags/[tagName]/page.tsx b/apps/web/app/dashboard/tags/[tagName]/page.tsx index 51b3cb0b..0c5c1c1f 100644 --- a/apps/web/app/dashboard/tags/[tagName]/page.tsx +++ b/apps/web/app/dashboard/tags/[tagName]/page.tsx @@ -2,10 +2,7 @@ import { notFound, redirect } from "next/navigation"; import BookmarksGrid from "@/components/dashboard/bookmarks/BookmarksGrid"; import { api } from "@/server/api/client"; import { getServerAuthSession } from "@/server/auth"; -import { and, eq } from "drizzle-orm"; - -import { db } from "@hoarder/db"; -import { bookmarkTags, tagsOnBookmarks } from "@hoarder/db/schema"; +import { TRPCError } from "@trpc/server"; export default async function TagPage({ params, @@ -17,30 +14,21 @@ export default async function TagPage({ redirect("/"); } const tagName = decodeURIComponent(params.tagName); - const tag = await db.query.bookmarkTags.findFirst({ - where: and( - eq(bookmarkTags.userId, session.user.id), - eq(bookmarkTags.name, tagName), - ), - columns: { - id: true, - }, - }); - if (!tag) { - // TODO: Better error message when the tag is not there - notFound(); + let tag; + try { + tag = await api.tags.get({ tagName }); + } catch (e) { + if (e instanceof TRPCError) { + if (e.code == "NOT_FOUND") { + notFound(); + } + } + throw e; } - const bookmarkIds = await db.query.tagsOnBookmarks.findMany({ - where: eq(tagsOnBookmarks.tagId, tag.id), - columns: { - bookmarkId: true, - }, - }); - const query = { - ids: bookmarkIds.map((b) => b.bookmarkId), + ids: tag.bookmarks, archived: false, }; |
