From 7ca3345ed6669781ec3c443b53eeeffbac27a549 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Fri, 25 Feb 2022 16:14:35 +0500 Subject: [PATCH] updating parent comment replies count if deeper replies are added --- src/components/comment/view/commentView.tsx | 12 ++++++++++++ .../comments/container/commentsContainer.js | 2 ++ src/components/comments/view/commentsView.tsx | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/components/comment/view/commentView.tsx b/src/components/comment/view/commentView.tsx index 315f4fa9d..b4e136efd 100644 --- a/src/components/comment/view/commentView.tsx +++ b/src/components/comment/view/commentView.tsx @@ -39,6 +39,7 @@ const CommentView = ({ hideManyCommentsButton, openReplyThread, fetchedAt, + incrementRepliesCount }) => { const intl = useIntl(); const actionSheet = useRef(null); @@ -77,6 +78,9 @@ const CommentView = ({ //TODO: update comment count and show sub comment if required; const cachedComment = cachedComments.get(postPath); if(cachedComment.updated === cachedComment.created){ + if(commentNumber > 1 && incrementRepliesCount){ + incrementRepliesCount(); + } setChildCount(childCount + 1); setReplies(replies ? [...replies, cachedComment] : [cachedComment]); } @@ -102,6 +106,13 @@ const CommentView = ({ setCacheVoteIcrement(1); }; + const _incrementRepliesCount = () => { + if(commentNumber > 1 && incrementRepliesCount){ + incrementRepliesCount(); + } + setChildCount(childCount + 1); + } + const _renderReadMoreButton = () => ( diff --git a/src/components/comments/container/commentsContainer.js b/src/components/comments/container/commentsContainer.js index 06c2f0995..72e177f22 100644 --- a/src/components/comments/container/commentsContainer.js +++ b/src/components/comments/container/commentsContainer.js @@ -46,6 +46,7 @@ const CommentsContainer = ({ hideManyCommentsButton, flatListProps, fetchedAt, + incrementRepliesCount, }) => { const lastCacheUpdate = useAppSelector((state) => state.cache.lastUpdate); const cachedComments = useAppSelector((state) => state.cache.comments); @@ -345,6 +346,7 @@ const CommentsContainer = ({ showAllComments={showAllComments} flatListProps={flatListProps} openReplyThread={_openReplyThread} + incrementRepliesCount={incrementRepliesCount} fetchedAt={fetchedAt} /> ); diff --git a/src/components/comments/view/commentsView.tsx b/src/components/comments/view/commentsView.tsx index 1c11d1c27..9e82da441 100644 --- a/src/components/comments/view/commentsView.tsx +++ b/src/components/comments/view/commentsView.tsx @@ -36,6 +36,7 @@ const CommentsView = ({ flatListProps, openReplyThread, fetchedAt, + incrementRepliesCount }) => { const [selectedComment, setSelectedComment] = useState(null); const intl = useIntl(); @@ -112,6 +113,7 @@ const CommentsView = ({ handleOnLongPress={() => _openCommentMenu(item)} openReplyThread={()=> _openReplyThread(item)} fetchedAt={fetchedAt} + incrementRepliesCount={incrementRepliesCount} /> ) };