onReplyRemoved method
Handles the removal of a comment reply.
Implementation
void onReplyRemoved(CommentData reply) {
final removeIndex = state.replies.indexWhere((it) => it.id == reply.id);
// If found at the top level, remove it directly
if (removeIndex >= 0) {
final updatedReplies = [...state.replies].apply(
(it) => it.removeAt(removeIndex),
);
state = state.copyWith(replies: updatedReplies);
return;
}
// Otherwise, it's a nested reply - find the parent reply and remove it
final updatedReplies = state.replies.updateNested(
(it) => it.id == reply.parentId,
children: (it) => it.replies ?? [],
update: (found) => found.removeReply(reply),
updateChildren: (parent, replies) => parent.copyWith(replies: replies),
);
state = state.copyWith(replies: updatedReplies);
}