diff --git a/src/components/Post.js b/src/components/Post.js index ea3da78..94ed370 100644 --- a/src/components/Post.js +++ b/src/components/Post.js @@ -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 (
setShowComments(!showComments)}> @@ -46,7 +53,7 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => {
- {post.comments.length} + {getComments(post)}