@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
24 lines • 877 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeCommentFromTree = removeCommentFromTree;
function removeCommentFromTree(state, commentId) {
const comment = state[commentId];
const newState = { ...state };
// Remove the comment itself
delete newState[commentId];
// Remove the comment from its parent’s replies
if (comment.comment?.parentId) {
const parent = newState[comment.comment.parentId];
const { [commentId]: _, ...remainingReplies } = parent.replies;
newState[comment.comment.parentId] = {
...parent,
replies: remainingReplies,
};
}
// Recursively remove all replies
Object.keys(comment.replies).forEach((replyId) => {
delete newState[replyId];
});
return newState;
}
//# sourceMappingURL=removeCommentFromTree.js.map