From 43362a383eca077beec0f88b24681681f7b6805c Mon Sep 17 00:00:00 2001 From: thierryverse Date: Wed, 12 Nov 2025 14:15:46 +0200 Subject: [PATCH] add delete chat mutation --- .../atoms/chats/mutations/delete-chat.mutation.atom.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/surfsense_web/atoms/chats/mutations/delete-chat.mutation.atom.ts b/surfsense_web/atoms/chats/mutations/delete-chat.mutation.atom.ts index 994906c24..b29f54f4e 100644 --- a/surfsense_web/atoms/chats/mutations/delete-chat.mutation.atom.ts +++ b/surfsense_web/atoms/chats/mutations/delete-chat.mutation.atom.ts @@ -4,6 +4,7 @@ import { activeSearchSpaceIdAtom } from "../../seach-spaces/active-seach-space.a import { queryClient } from "@/lib/query-client/client"; import { cacheKeys } from "@/lib/query-client/cache-keys"; import { toast } from "sonner"; +import { Chat } from "@/app/dashboard/[search_space_id]/chats/chats-client"; export const deleteChatMutationAtom = atomWithMutation((get) => { const searchSpaceId = get(activeSearchSpaceIdAtom); @@ -23,10 +24,10 @@ export const deleteChatMutationAtom = atomWithMutation((get) => { return deleteChat(chatId, authToken); }, - onSuccess: () => { + onSuccess: (_, chatId) => { toast.success("Chat deleted successfully"); - queryClient.invalidateQueries({ - queryKey: cacheKeys.activeSearchSpace.chats(searchSpaceId!), + queryClient.setQueryData(cacheKeys.activeSearchSpace.chats(searchSpaceId!), (oldData: Chat[]) => { + return oldData.filter((chat) => chat.id !== chatId); }); }, };