fixed wrong recursion comment count if there are not displayed comments

This commit is contained in:
2024-06-13 08:21:25 +02:00
parent caf853e8a9
commit 475c490b16

View File

@@ -32,10 +32,10 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => {
postApi.reactToPost(post.id, null).then(reload); postApi.reactToPost(post.id, null).then(reload);
} }
const getComments = (post) => { const getComments = (post, recursionDepth) => {
let nrOfComments = post.comments.length; let nrOfComments = post.comments.length;
post.comments.forEach(comment => { if (recursionDepth !== 0) post.comments.forEach(comment => {
nrOfComments += getComments(comment); nrOfComments += getComments(comment, recursionDepth - 1);
}) })
return nrOfComments; return nrOfComments;
} }
@@ -53,7 +53,7 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => {
</div> </div>
{recursionDepth !== 0 && <div className="nrOfComments"> {recursionDepth !== 0 && <div className="nrOfComments">
<FontAwesomeIcon className="icon" icon={faComments}/> <FontAwesomeIcon className="icon" icon={faComments}/>
<span className="">{getComments(post)}</span> <span className="">{getComments(post, recursionDepth-1)}</span>
</div>} </div>}
<div className="post-right"> <div className="post-right">
<div className="post-date"> <div className="post-date">