From bbd6f9012043a9b3cbf08b5b8ab46858e424e900 Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 21 Jan 2024 11:15:27 +0800 Subject: [PATCH] fix: comment reply mutation Signed-off-by: Innei --- src/queries/definition/comment.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/queries/definition/comment.ts b/src/queries/definition/comment.ts index c6ab7e290f..a77bfe0ff8 100644 --- a/src/queries/definition/comment.ts +++ b/src/queries/definition/comment.ts @@ -109,13 +109,24 @@ export const useReplyCommentMutation = () => { }, }) }, - onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: commentAdmin.byState(state).queryKey, - }) + onMutate({ id }) { + queryClient.setQueryData>>( + commentAdmin.byState(state).queryKey, + produce((draft) => { + draft?.pages.forEach((page) => { + page.data = page.data.filter((comment) => comment.id !== id) + }) + }), + ) + }, + onSuccess: (_) => { toast.success('回复成功') }, onError: () => { + queryClient.invalidateQueries({ + queryKey: commentAdmin.byState(state).queryKey, + }) + toast.error('回复失败') }, })