From 02573a67caa19838a8e7f2fd9a10de227b94d602 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 22 May 2024 11:35:09 +0800 Subject: [PATCH] feat: setQueryData after collecting and uncollecting --- src/renderer/src/hooks/useEntryActions.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/hooks/useEntryActions.tsx b/src/renderer/src/hooks/useEntryActions.tsx index 3f214f547..cff88b5d3 100644 --- a/src/renderer/src/hooks/useEntryActions.tsx +++ b/src/renderer/src/hooks/useEntryActions.tsx @@ -35,9 +35,14 @@ export const useEntryActions = ({ }, }), onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: ["entries"], - }) + queryClient.setQueryData( + ["entry", entry.id], + Object.assign({}, entry, { + collections: { + createdAt: new Date().toISOString(), + }, + }), + ) toast({ duration: 1000, description: "Collected.", @@ -53,9 +58,12 @@ export const useEntryActions = ({ }, }), onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: ["entries"], - }) + queryClient.setQueryData( + ["entry", entry.id], + Object.assign({}, entry, { + collections: null, + }), + ) toast({ duration: 1000, description: "Uncollected.",