⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
Fix endpoint & useMutation callback
Isaac102cd1a6cfe6
diff --git a/hooks/store/tags.tsx b/hooks/store/tags.tsxindex da290e94..5602c9ab 100644--- a/hooks/store/tags.tsx+++ b/hooks/store/tags.tsx@@ -66,8 +66,17 @@ const useUpdateArchivalTags = () => {return data.response;},- onSettled: () => {- queryClient.invalidateQueries({ queryKey: ["tags"] });+ onSuccess: (data: TagIncludingLinkCount[]) => {+ queryClient.setQueryData(["tags"], (oldData: TagIncludingLinkCount[] = []) => {+ const updatedTags = oldData.map((tag) => {+ const updatedTag = data.find((t) => t.id === tag.id);+ return updatedTag ? { ...tag, ...updatedTag } : tag;+ });++ const newTags = data.filter((t) => !oldData.some((tag) => tag.id === t.id));++ return [...updatedTags, ...newTags];+ });},});}diff --git a/pages/api/v1/tags/archival/index.ts b/pages/api/v1/tags/archival/index.tsindex 8c98fd3b..ac24d672 100644--- a/pages/api/v1/tags/archival/index.ts+++ b/pages/api/v1/tags/archival/index.ts@@ -1,6 +1,7 @@import { prisma } from "@/lib/api/db";import verifyUser from "@/lib/api/verifyUser";import { PostArchivalTagSchema } from "@/lib/shared/schemaValidation";+import { Tag } from "@prisma/client";import { NextApiRequest, NextApiResponse } from "next";export default async function archivalTags(req: NextApiRequest, res: NextApiResponse) {@@ -18,6 +19,7 @@ export default async function archivalTags(req: NextApiRequest, res: NextApiResp}const { tags } = dataValidation.data;+ const updatedTags: Tag[] = []for (const tag of tags) {if (tag.newTag) {@@ -31,7 +33,7 @@ export default async function archivalTags(req: NextApiRequest, res: NextApiResp// If the tag name is already taken by the user, skip creating a new tagif (tagNameIsTaken) return- await prisma.tag.create({+ const newTag = await prisma.tag.create({data: {name: tag.label,ownerId: user.id,@@ -42,7 +44,11 @@ export default async function archivalTags(req: NextApiRequest, res: NextApiResparchiveAsWaybackMachine: tag.archiveAsWaybackMachine,aiTag: tag.aiTag,},+ include: {+ _count: true,+ }});+ updatedTags.push(newTag);} else {const targetTag = await prisma.tag.findUnique({where: {@@ -56,7 +62,7 @@ export default async function archivalTags(req: NextApiRequest, res: NextApiResp// If the tag is not found or the ownerId does not match, skip updatingif (targetTag && targetTag.ownerId !== user.id) return- await prisma.tag.update({+ const updatedTag = await prisma.tag.update({where: {name_ownerId: {name: tag.label,@@ -71,10 +77,14 @@ export default async function archivalTags(req: NextApiRequest, res: NextApiResparchiveAsWaybackMachine: tag.archiveAsWaybackMachine,aiTag: tag.aiTag,},+ include: {+ _count: true,+ }});+ updatedTags.push(updatedTag);}}- return res.status(200).json({ response: "Tags updated successfully." });+ return res.status(200).json({ response: updatedTags });}}