From 475c490b16cec81f6f39120b603b7efe12118ff3 Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Thu, 13 Jun 2024 08:21:25 +0200 Subject: [PATCH] fixed wrong recursion comment count if there are not displayed comments --- src/components/Post.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Post.js b/src/components/Post.js index f01dfd4..634a330 100644 --- a/src/components/Post.js +++ b/src/components/Post.js @@ -32,10 +32,10 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => { postApi.reactToPost(post.id, null).then(reload); } - const getComments = (post) => { + const getComments = (post, recursionDepth) => { let nrOfComments = post.comments.length; - post.comments.forEach(comment => { - nrOfComments += getComments(comment); + if (recursionDepth !== 0) post.comments.forEach(comment => { + nrOfComments += getComments(comment, recursionDepth - 1); }) return nrOfComments; } @@ -53,7 +53,7 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => { {recursionDepth !== 0 &&
- {getComments(post)} + {getComments(post, recursionDepth-1)}
}