Skip to content

Commit

Permalink
fix: comment reply mutation
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jan 21, 2024
1 parent 59d1944 commit bbd6f90
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/queries/definition/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,24 @@ export const useReplyCommentMutation = () => {
},
})
},
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: commentAdmin.byState(state).queryKey,
})
onMutate({ id }) {
queryClient.setQueryData<InfiniteData<PaginateResult<CommentModel>>>(
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('回复失败')
},
})
Expand Down

0 comments on commit bbd6f90

Please sign in to comment.