From 62f7d900c52784ff05d933b52379e5455ea6bd00 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 28 Sep 2025 11:03:48 +0100 Subject: feat: Add tag search and pagination (#1987) * feat: Add tag search and use in the homepage * use paginated query in the all tags view * wire the load more buttons * add skeleton to all tags page * fix attachedby aggregation * fix loading states * fix hasNextPage * use action buttons for load more buttons * migrate the tags auto complete to the search api * Migrate the tags editor to the new search API * Replace tag merging dialog with tag auto completion * Merge both search and list APIs * fix tags.list * add some tests for the endpoint * add relevance based sorting * change cursor * update the REST API * fix review comments * more fixes * fix lockfile * i18n * fix visible tags --- packages/api/routes/tags.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'packages/api/routes') diff --git a/packages/api/routes/tags.ts b/packages/api/routes/tags.ts index 816e58b4..79e36e99 100644 --- a/packages/api/routes/tags.ts +++ b/packages/api/routes/tags.ts @@ -1,8 +1,11 @@ import { zValidator } from "@hono/zod-validator"; import { Hono } from "hono"; +import { z } from "zod"; import { zCreateTagRequestSchema, + zTagListApiResultSchema, + zTagListQueryParamsSchema, zUpdateTagRequestSchema, } from "@karakeep/shared/types/tags"; @@ -14,9 +17,23 @@ const app = new Hono() .use(authMiddleware) // GET /tags - .get("/", async (c) => { - const tags = await c.var.api.tags.list(); - return c.json(tags, 200); + .get("/", zValidator("query", zTagListQueryParamsSchema), async (c) => { + const searchParams = c.req.valid("query"); + const tags = await c.var.api.tags.list({ + nameContains: searchParams.nameContains, + attachedBy: searchParams.attachedBy, + sortBy: searchParams.sort, + cursor: searchParams.cursor, + limit: searchParams.limit, + }); + + const resp: z.infer = { + tags: tags.tags, + nextCursor: tags.nextCursor + ? Buffer.from(JSON.stringify(tags.nextCursor)).toString("base64url") + : null, + }; + return c.json(resp, 200); }) // POST /tags -- cgit v1.2.3-70-g09d2