diff --git a/src/components/comment/view/commentView.tsx b/src/components/comment/view/commentView.tsx index 0a0a42a97..b136f5704 100644 --- a/src/components/comment/view/commentView.tsx +++ b/src/components/comment/view/commentView.tsx @@ -40,6 +40,7 @@ const CommentView = ({ isShowSubComments, hideManyCommentsButton, openReplyThread, + fetchedAt, }) => { const intl = useIntl(); const actionSheet = useRef(null); @@ -111,6 +112,7 @@ const CommentView = ({ fetchPost={fetchPost} hideManyCommentsButton={hideManyCommentsButton} mainAuthor={mainAuthor} + fetchedAt={fetchedAt} /> diff --git a/src/components/comments/container/commentsContainer.js b/src/components/comments/container/commentsContainer.js index 7cd8d4f52..16276e802 100644 --- a/src/components/comments/container/commentsContainer.js +++ b/src/components/comments/container/commentsContainer.js @@ -51,6 +51,7 @@ const CommentsContainer = ({ const cachedComments = useAppSelector((state) => state.cache.comments); const [lcomments, setLComments] = useState([]); + const [replies, setReplies] = useState(comments); const [selectedPermlink, setSelectedPermlink] = useState(''); useEffect(() => { @@ -160,7 +161,7 @@ const CommentsContainer = ({ const _getComments = async () => { if (isOwnProfile) { fetchPost(); - } else if (author && permlink && !comments) { + } else if (author && permlink && !replies) { await getComments(author, permlink, name) .then((__comments) => { //TODO: favourable place for merging comment cache @@ -177,7 +178,7 @@ const CommentsContainer = ({ }; const _handleCachedComment = (passedComments = null) => { - const comments = passedComments || lcomments; + const _comments = passedComments || replies || lcomments; const postPath = `${author || ''}/${permlink || ''}`; if (cachedComments.has(postPath)) { @@ -185,7 +186,7 @@ const CommentsContainer = ({ var ignoreCache = false; var replaceAtIndex = -1; - comments.forEach((comment, index) => { + _comments.forEach((comment, index) => { if (cachedComment.permlink === comment.permlink) { if (cachedComment.updated < comment.updated) { //comment is present with latest data @@ -202,21 +203,23 @@ const CommentsContainer = ({ if (!ignoreCache) { let newComments = []; if (replaceAtIndex >= 0) { - comments[replaceAtIndex] = cachedComment; - newComments = [...comments]; + _comments[replaceAtIndex] = cachedComment; + newComments = [..._comments]; } else { - newComments = [...comments, cachedComment]; + newComments = [..._comments, cachedComment]; } console.log('updated comments with cached comment'); if (passedComments) { return newComments; + } else if (replies) { + setReplies(newComments); } else { setLComments(newComments); } } } - return comments; + return _comments; }; const _handleOnReplyPress = (item) => { @@ -313,7 +316,7 @@ const CommentsContainer = ({ isShowMoreButton={isShowMoreButton} commentNumber={commentNumber || 1} commentCount={commentCount} - comments={lcomments.length > 0 ? lcomments : comments} + comments={lcomments.length > 0 ? lcomments : replies} currentAccountUsername={currentAccount.name} handleOnEditPress={_handleOnEditPress} handleOnReplyPress={_handleOnReplyPress} @@ -328,6 +331,7 @@ const CommentsContainer = ({ showAllComments={showAllComments} flatListProps={flatListProps} openReplyThread={_openReplyThread} + fetchedAt={fetchedAt} /> ); }; diff --git a/src/components/comments/view/commentsView.tsx b/src/components/comments/view/commentsView.tsx index 4ad323285..db212f957 100644 --- a/src/components/comments/view/commentsView.tsx +++ b/src/components/comments/view/commentsView.tsx @@ -36,6 +36,7 @@ const CommentsView = ({ hideManyCommentsButton, flatListProps, openReplyThread, + fetchedAt, }) => { const [selectedComment, setSelectedComment] = useState(null); const intl = useIntl(); @@ -112,6 +113,7 @@ const CommentsView = ({ marginLeft={marginLeft} handleOnLongPress={() => _openCommentMenu(item)} openReplyThread={()=> _openReplyThread(item)} + fetchedAt={fetchedAt} /> ) };