From 63f1c04633a070842a7e2bb2f4d6e70a0cf41e4b Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 2 Mar 2021 19:34:24 +0500 Subject: [PATCH] attempting to improve postcardContainer --- .../postCard/container/postCardContainer.js | 13 +++++++------ src/components/postCard/view/postCardView.js | 2 -- src/components/posts/view/postsView.js | 1 + src/providers/hive/dhive.js | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/postCard/container/postCardContainer.js b/src/components/postCard/container/postCardContainer.js index 096b37823..cc3758154 100644 --- a/src/components/postCard/container/postCardContainer.js +++ b/src/components/postCard/container/postCardContainer.js @@ -28,13 +28,14 @@ const PostCardContainer = ({ isHideImage, nsfw, }) => { - const [activeVotes, setActiveVotes] = useState([]); + const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', [])); const [reblogs, setReblogs] = useState([]); const [_content, setContent] = useState(content); + //NOTE: potentially unnessacry fetch // useEffect(() => { // if (isRefresh) { - // _fetchPost(); + // _fetchPost(); // } // }, [isRefresh]); @@ -57,8 +58,8 @@ const PostCardContainer = ({ }; if (_content) { - setActiveVotes(get(_content, 'active_votes', [])); - setContent(_content); + //no need to reset content here, it is already set + // setContent(_content); fetchData(_content); } @@ -122,6 +123,7 @@ const PostCardContainer = ({ .then((result) => { if (result) { setContent(result); + setActiveVotes(get(result, 'active_votes', [])) } }) .catch(() => {}); @@ -136,8 +138,7 @@ const PostCardContainer = ({ fetchPost={_fetchPost} content={_content || content} isHideImage={isHideImage} - isNsfwPost={nsfw === '1'} - activeVotes={activeVotes} + isNsfwPost={nsfw || '1'} reblogs={reblogs} /> ); diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index dd5d4396a..0dda7b998 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -36,7 +36,6 @@ const PostCardView = ({ fetchPost, isNsfwPost, intl, - activeVotes, }) => { // const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null)); // const [activeVot, setActiveVot] = useState(activeVotes); @@ -44,7 +43,6 @@ const PostCardView = ({ // const [calcImgHeight, setCalcImgHeight] = useState(300); const calcImgHeight = 300; - // Component Functions const _handleOnUserPress = () => { diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index 8badf4297..6d533f192 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -323,6 +323,7 @@ const PostsView = ({ _onEndReachedCalledDuringMomentum = false; }} removeClippedSubviews + //TODO: we can avoid 2 more rerenders by carefully moving these call to postsListContainer refreshing={refreshing} onRefresh={handleOnRefreshPosts} onEndReachedThreshold={1} diff --git a/src/providers/hive/dhive.js b/src/providers/hive/dhive.js index f33f4e9a0..099184ef2 100644 --- a/src/providers/hive/dhive.js +++ b/src/providers/hive/dhive.js @@ -514,7 +514,6 @@ export const getPost = async (author, permlink, currentUserName = null, isPromot try { console.log('Getting post: ', author, permlink); const post = await client.database.call('get_content', [author, permlink]); - return post ? parsePost(post, currentUserName, isPromoted) : null; } catch (error) { return error;