From 8618f31a548e2266b05b47d62bba2a3003184ace Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 20 Feb 2024 15:00:55 +0000 Subject: fix: Fix passing the query to the tag page --- packages/web/app/dashboard/tags/[tagName]/page.tsx | 8 +++-- packages/web/lib/types/api/bookmarks.ts | 1 + packages/web/server/api/routers/bookmarks.ts | 34 ++++------------------ 3 files changed, 11 insertions(+), 32 deletions(-) (limited to 'packages/web') diff --git a/packages/web/app/dashboard/tags/[tagName]/page.tsx b/packages/web/app/dashboard/tags/[tagName]/page.tsx index a95b0f90..729a5cbc 100644 --- a/packages/web/app/dashboard/tags/[tagName]/page.tsx +++ b/packages/web/app/dashboard/tags/[tagName]/page.tsx @@ -39,15 +39,17 @@ export default async function TagPage({ }, }); - const bookmarks = await api.bookmarks.getBookmarksById({ + const query = { ids: bookmarkIds.map((b) => b.bookmarkId), archived: false, - }); + }; + + const bookmarks = await api.bookmarks.getBookmarks(query); return (
#{params.tagName} - +
); } diff --git a/packages/web/lib/types/api/bookmarks.ts b/packages/web/lib/types/api/bookmarks.ts index 3d70f868..772ef153 100644 --- a/packages/web/lib/types/api/bookmarks.ts +++ b/packages/web/lib/types/api/bookmarks.ts @@ -33,6 +33,7 @@ export type ZNewBookmarkRequest = z.infer; // GET /v1/bookmarks export const zGetBookmarksRequestSchema = z.object({ + ids: z.array(z.string()).optional(), archived: z.boolean().optional(), favourited: z.boolean().optional(), }); diff --git a/packages/web/server/api/routers/bookmarks.ts b/packages/web/server/api/routers/bookmarks.ts index 1a78724d..29911bb3 100644 --- a/packages/web/server/api/routers/bookmarks.ts +++ b/packages/web/server/api/routers/bookmarks.ts @@ -163,35 +163,11 @@ export const bookmarksAppRouter = router({ userId: ctx.user.id, archived: input.archived, favourited: input.favourited, - }, - orderBy: { - createdAt: "desc", - }, - select: defaultBookmarkFields, - }) - ).map(toZodSchema); - - return { bookmarks }; - }), - getBookmarksById: authedProcedure - .input( - zGetBookmarksRequestSchema.merge( - z.object({ - ids: z.array(z.string()), - }), - ), - ) - .output(zGetBookmarksResponseSchema) - .query(async ({ input, ctx }) => { - const bookmarks = ( - await prisma.bookmark.findMany({ - where: { - id: { - in: input.ids, - }, - userId: ctx.user.id, - archived: input.archived, - favourited: input.favourited, + id: input.ids + ? { + in: input.ids, + } + : undefined, }, orderBy: { createdAt: "desc", -- cgit v1.2.3-70-g09d2