fixed wrong recursion comment count if there are not displayed comments
This commit is contained in:
@@ -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 }) => {
|
||||
</div>
|
||||
{recursionDepth !== 0 && <div className="nrOfComments">
|
||||
<FontAwesomeIcon className="icon" icon={faComments}/>
|
||||
<span className="">{getComments(post)}</span>
|
||||
<span className="">{getComments(post, recursionDepth-1)}</span>
|
||||
</div>}
|
||||
<div className="post-right">
|
||||
<div className="post-date">
|
||||
|
||||
Reference in New Issue
Block a user