recursive comment count
This commit is contained in:
@@ -3,7 +3,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faCaretUp,
|
||||
faCaretDown,
|
||||
faCommentAlt,
|
||||
faComments,
|
||||
faAngleUp,
|
||||
faAngleDown
|
||||
@@ -33,6 +32,14 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => {
|
||||
postApi.reactToPost(post.id, null).then(reload);
|
||||
}
|
||||
|
||||
const getComments = (post) => {
|
||||
let nrOfComments = post.comments.length;
|
||||
post.comments.forEach(comment => {
|
||||
nrOfComments += getComments(comment);
|
||||
})
|
||||
return nrOfComments;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="post" onClick={() => setShowComments(!showComments)}>
|
||||
@@ -46,7 +53,7 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => {
|
||||
</div>
|
||||
<div className="nrOfComments">
|
||||
<FontAwesomeIcon className="icon" icon={faComments}/>
|
||||
<span className="">{post.comments.length}</span>
|
||||
<span className="">{getComments(post)}</span>
|
||||
</div>
|
||||
<div className="post-right">
|
||||
<div className="post-date">
|
||||
|
||||
Reference in New Issue
Block a user