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('回复失败') }, })