Skip to content

Commit bbd6f90

Browse files
committed
fix: comment reply mutation
Signed-off-by: Innei <[email protected]>
1 parent 59d1944 commit bbd6f90

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/queries/definition/comment.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,24 @@ export const useReplyCommentMutation = () => {
109109
},
110110
})
111111
},
112-
onSuccess: () => {
113-
queryClient.invalidateQueries({
114-
queryKey: commentAdmin.byState(state).queryKey,
115-
})
112+
onMutate({ id }) {
113+
queryClient.setQueryData<InfiniteData<PaginateResult<CommentModel>>>(
114+
commentAdmin.byState(state).queryKey,
115+
produce((draft) => {
116+
draft?.pages.forEach((page) => {
117+
page.data = page.data.filter((comment) => comment.id !== id)
118+
})
119+
}),
120+
)
121+
},
122+
onSuccess: (_) => {
116123
toast.success('回复成功')
117124
},
118125
onError: () => {
126+
queryClient.invalidateQueries({
127+
queryKey: commentAdmin.byState(state).queryKey,
128+
})
129+
119130
toast.error('回复失败')
120131
},
121132
})

0 commit comments

Comments
 (0)