mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 21:01:31 +03:00
added support for caching reply to comments
This commit is contained in:
parent
3d1b11fe8d
commit
1a3ced39de
@ -40,6 +40,7 @@ const CommentView = ({
|
|||||||
isShowSubComments,
|
isShowSubComments,
|
||||||
hideManyCommentsButton,
|
hideManyCommentsButton,
|
||||||
openReplyThread,
|
openReplyThread,
|
||||||
|
fetchedAt,
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const actionSheet = useRef(null);
|
const actionSheet = useRef(null);
|
||||||
@ -111,6 +112,7 @@ const CommentView = ({
|
|||||||
fetchPost={fetchPost}
|
fetchPost={fetchPost}
|
||||||
hideManyCommentsButton={hideManyCommentsButton}
|
hideManyCommentsButton={hideManyCommentsButton}
|
||||||
mainAuthor={mainAuthor}
|
mainAuthor={mainAuthor}
|
||||||
|
fetchedAt={fetchedAt}
|
||||||
/>
|
/>
|
||||||
</AnimatedView>
|
</AnimatedView>
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ const CommentsContainer = ({
|
|||||||
const cachedComments = useAppSelector((state) => state.cache.comments);
|
const cachedComments = useAppSelector((state) => state.cache.comments);
|
||||||
|
|
||||||
const [lcomments, setLComments] = useState([]);
|
const [lcomments, setLComments] = useState([]);
|
||||||
|
const [replies, setReplies] = useState(comments);
|
||||||
const [selectedPermlink, setSelectedPermlink] = useState('');
|
const [selectedPermlink, setSelectedPermlink] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -160,7 +161,7 @@ const CommentsContainer = ({
|
|||||||
const _getComments = async () => {
|
const _getComments = async () => {
|
||||||
if (isOwnProfile) {
|
if (isOwnProfile) {
|
||||||
fetchPost();
|
fetchPost();
|
||||||
} else if (author && permlink && !comments) {
|
} else if (author && permlink && !replies) {
|
||||||
await getComments(author, permlink, name)
|
await getComments(author, permlink, name)
|
||||||
.then((__comments) => {
|
.then((__comments) => {
|
||||||
//TODO: favourable place for merging comment cache
|
//TODO: favourable place for merging comment cache
|
||||||
@ -177,7 +178,7 @@ const CommentsContainer = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const _handleCachedComment = (passedComments = null) => {
|
const _handleCachedComment = (passedComments = null) => {
|
||||||
const comments = passedComments || lcomments;
|
const _comments = passedComments || replies || lcomments;
|
||||||
const postPath = `${author || ''}/${permlink || ''}`;
|
const postPath = `${author || ''}/${permlink || ''}`;
|
||||||
|
|
||||||
if (cachedComments.has(postPath)) {
|
if (cachedComments.has(postPath)) {
|
||||||
@ -185,7 +186,7 @@ const CommentsContainer = ({
|
|||||||
|
|
||||||
var ignoreCache = false;
|
var ignoreCache = false;
|
||||||
var replaceAtIndex = -1;
|
var replaceAtIndex = -1;
|
||||||
comments.forEach((comment, index) => {
|
_comments.forEach((comment, index) => {
|
||||||
if (cachedComment.permlink === comment.permlink) {
|
if (cachedComment.permlink === comment.permlink) {
|
||||||
if (cachedComment.updated < comment.updated) {
|
if (cachedComment.updated < comment.updated) {
|
||||||
//comment is present with latest data
|
//comment is present with latest data
|
||||||
@ -202,21 +203,23 @@ const CommentsContainer = ({
|
|||||||
if (!ignoreCache) {
|
if (!ignoreCache) {
|
||||||
let newComments = [];
|
let newComments = [];
|
||||||
if (replaceAtIndex >= 0) {
|
if (replaceAtIndex >= 0) {
|
||||||
comments[replaceAtIndex] = cachedComment;
|
_comments[replaceAtIndex] = cachedComment;
|
||||||
newComments = [...comments];
|
newComments = [..._comments];
|
||||||
} else {
|
} else {
|
||||||
newComments = [...comments, cachedComment];
|
newComments = [..._comments, cachedComment];
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('updated comments with cached comment');
|
console.log('updated comments with cached comment');
|
||||||
if (passedComments) {
|
if (passedComments) {
|
||||||
return newComments;
|
return newComments;
|
||||||
|
} else if (replies) {
|
||||||
|
setReplies(newComments);
|
||||||
} else {
|
} else {
|
||||||
setLComments(newComments);
|
setLComments(newComments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return comments;
|
return _comments;
|
||||||
};
|
};
|
||||||
|
|
||||||
const _handleOnReplyPress = (item) => {
|
const _handleOnReplyPress = (item) => {
|
||||||
@ -313,7 +316,7 @@ const CommentsContainer = ({
|
|||||||
isShowMoreButton={isShowMoreButton}
|
isShowMoreButton={isShowMoreButton}
|
||||||
commentNumber={commentNumber || 1}
|
commentNumber={commentNumber || 1}
|
||||||
commentCount={commentCount}
|
commentCount={commentCount}
|
||||||
comments={lcomments.length > 0 ? lcomments : comments}
|
comments={lcomments.length > 0 ? lcomments : replies}
|
||||||
currentAccountUsername={currentAccount.name}
|
currentAccountUsername={currentAccount.name}
|
||||||
handleOnEditPress={_handleOnEditPress}
|
handleOnEditPress={_handleOnEditPress}
|
||||||
handleOnReplyPress={_handleOnReplyPress}
|
handleOnReplyPress={_handleOnReplyPress}
|
||||||
@ -328,6 +331,7 @@ const CommentsContainer = ({
|
|||||||
showAllComments={showAllComments}
|
showAllComments={showAllComments}
|
||||||
flatListProps={flatListProps}
|
flatListProps={flatListProps}
|
||||||
openReplyThread={_openReplyThread}
|
openReplyThread={_openReplyThread}
|
||||||
|
fetchedAt={fetchedAt}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -36,6 +36,7 @@ const CommentsView = ({
|
|||||||
hideManyCommentsButton,
|
hideManyCommentsButton,
|
||||||
flatListProps,
|
flatListProps,
|
||||||
openReplyThread,
|
openReplyThread,
|
||||||
|
fetchedAt,
|
||||||
}) => {
|
}) => {
|
||||||
const [selectedComment, setSelectedComment] = useState(null);
|
const [selectedComment, setSelectedComment] = useState(null);
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@ -112,6 +113,7 @@ const CommentsView = ({
|
|||||||
marginLeft={marginLeft}
|
marginLeft={marginLeft}
|
||||||
handleOnLongPress={() => _openCommentMenu(item)}
|
handleOnLongPress={() => _openCommentMenu(item)}
|
||||||
openReplyThread={()=> _openReplyThread(item)}
|
openReplyThread={()=> _openReplyThread(item)}
|
||||||
|
fetchedAt={fetchedAt}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user