diff --git a/frontend/src/components/dreps/notes/SingleNote.tsx b/frontend/src/components/dreps/notes/SingleNote.tsx index eaf7390edd90140c6ce79e861a8c8fe2ce2c40b6..b4b1f22e49713a2035c2ee70cb915159696d83a2 100644 --- a/frontend/src/components/dreps/notes/SingleNote.tsx +++ b/frontend/src/components/dreps/notes/SingleNote.tsx @@ -101,6 +101,22 @@ const SingleNote = ({ } setIsCommenting(true); }; + const countTotalComments = (comments) => { + // If there are no comments, return 0 + if (!comments || comments.length === 0) return 0; + + let totalCount = comments.length; // Counting top-level comments + + // Loop through each comment + comments.forEach(comment => { + // Recursively count the responses (nested comments) + if (comment.comments && comment.comments.length > 0) { + totalCount += countTotalComments(comment.comments); // Add nested comment count + } + }); + + return totalCount; + }; const handleReaction = async (type) => { //to prevent orphan reaction till say wallet is done connecting if (!isEnabled) { @@ -180,6 +196,7 @@ const SingleNote = ({ reset({ comment: '' }); setIsCommenting(false); handleRefetch(); + setShowResponses(true); } catch (error) { console.log(error); } @@ -261,7 +278,7 @@ const SingleNote = ({ } }} > - {showResponses ? 'Hide' : 'View'} Responses + {showResponses ? 'Hide' : 'View'} Responses ({countTotalComments(currentComments)}) </Button> </div> <div className="flex gap-5">