mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-09 07:42:39 +02:00
add delete chat mutation
This commit is contained in:
parent
b866170e6a
commit
43362a383e
1 changed files with 4 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import { activeSearchSpaceIdAtom } from "../../seach-spaces/active-seach-space.a
|
||||||
import { queryClient } from "@/lib/query-client/client";
|
import { queryClient } from "@/lib/query-client/client";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { Chat } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
||||||
|
|
||||||
export const deleteChatMutationAtom = atomWithMutation((get) => {
|
export const deleteChatMutationAtom = atomWithMutation((get) => {
|
||||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||||
|
|
@ -23,10 +24,10 @@ export const deleteChatMutationAtom = atomWithMutation((get) => {
|
||||||
return deleteChat(chatId, authToken);
|
return deleteChat(chatId, authToken);
|
||||||
},
|
},
|
||||||
|
|
||||||
onSuccess: () => {
|
onSuccess: (_, chatId) => {
|
||||||
toast.success("Chat deleted successfully");
|
toast.success("Chat deleted successfully");
|
||||||
queryClient.invalidateQueries({
|
queryClient.setQueryData(cacheKeys.activeSearchSpace.chats(searchSpaceId!), (oldData: Chat[]) => {
|
||||||
queryKey: cacheKeys.activeSearchSpace.chats(searchSpaceId!),
|
return oldData.filter((chat) => chat.id !== chatId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue