Skip to content

Commit 4baa313

Browse files
fix count (codesandbox#3828)
1 parent adbcc01 commit 4baa313

File tree

1 file changed

+14
-1
lines changed
  • packages/app/src/app/overmind/namespaces/comments

1 file changed

+14
-1
lines changed

packages/app/src/app/overmind/namespaces/comments/actions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,18 @@ export const deleteComment: AsyncAction<{
380380
const sandboxId = state.editor.currentSandbox.id;
381381
const comments = state.comments.comments;
382382
const deletedComment = comments[sandboxId][commentId];
383-
383+
const parentComment =
384+
deletedComment.parentComment &&
385+
comments[sandboxId][deletedComment.parentComment.id];
384386
delete comments[sandboxId][commentId];
387+
let replyIndex: number = -1;
388+
389+
if (parentComment) {
390+
replyIndex = parentComment.comments.findIndex(
391+
reply => reply.id === deletedComment.id
392+
);
393+
parentComment.comments.splice(replyIndex, 1);
394+
}
385395

386396
try {
387397
await effects.gql.mutations.deleteComment({
@@ -393,6 +403,9 @@ export const deleteComment: AsyncAction<{
393403
'Unable to delete your comment, please try again'
394404
);
395405
comments[sandboxId][commentId] = deletedComment;
406+
if (parentComment) {
407+
parentComment.comments.splice(replyIndex, 0, { id: deletedComment.id });
408+
}
396409
}
397410
};
398411

0 commit comments

Comments
 (0)