updating parent comment replies count if deeper replies are added

This commit is contained in:
noumantahir 2022-02-25 16:14:35 +05:00
parent b0fbedcb82
commit 7ca3345ed6
3 changed files with 16 additions and 0 deletions

View File

@ -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 = () => (
<TextWithIcon
@ -139,6 +150,7 @@ const CommentView = ({
hideManyCommentsButton={hideManyCommentsButton}
mainAuthor={mainAuthor}
fetchedAt={fetchedAt}
incrementRepliesCount={_incrementRepliesCount}
/>
</AnimatedView>

View File

@ -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}
/>
);

View File

@ -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}
/>
)
};