recursive comment count

This commit is contained in:
2024-06-12 19:26:15 +02:00
parent 9a515baf37
commit d8050f68cd

View File

@@ -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">