attempting to improve postcardContainer

This commit is contained in:
Nouman Tahir 2021-03-02 19:34:24 +05:00
parent 3ccade57a6
commit 63f1c04633
4 changed files with 8 additions and 9 deletions

View File

@ -28,13 +28,14 @@ const PostCardContainer = ({
isHideImage, isHideImage,
nsfw, nsfw,
}) => { }) => {
const [activeVotes, setActiveVotes] = useState([]); const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', []));
const [reblogs, setReblogs] = useState([]); const [reblogs, setReblogs] = useState([]);
const [_content, setContent] = useState(content); const [_content, setContent] = useState(content);
//NOTE: potentially unnessacry fetch
// useEffect(() => { // useEffect(() => {
// if (isRefresh) { // if (isRefresh) {
// _fetchPost(); // _fetchPost();
// } // }
// }, [isRefresh]); // }, [isRefresh]);
@ -57,8 +58,8 @@ const PostCardContainer = ({
}; };
if (_content) { if (_content) {
setActiveVotes(get(_content, 'active_votes', [])); //no need to reset content here, it is already set
setContent(_content); // setContent(_content);
fetchData(_content); fetchData(_content);
} }
@ -122,6 +123,7 @@ const PostCardContainer = ({
.then((result) => { .then((result) => {
if (result) { if (result) {
setContent(result); setContent(result);
setActiveVotes(get(result, 'active_votes', []))
} }
}) })
.catch(() => {}); .catch(() => {});
@ -136,8 +138,7 @@ const PostCardContainer = ({
fetchPost={_fetchPost} fetchPost={_fetchPost}
content={_content || content} content={_content || content}
isHideImage={isHideImage} isHideImage={isHideImage}
isNsfwPost={nsfw === '1'} isNsfwPost={nsfw || '1'}
activeVotes={activeVotes}
reblogs={reblogs} reblogs={reblogs}
/> />
); );

View File

@ -36,7 +36,6 @@ const PostCardView = ({
fetchPost, fetchPost,
isNsfwPost, isNsfwPost,
intl, intl,
activeVotes,
}) => { }) => {
// const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null)); // const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null));
// const [activeVot, setActiveVot] = useState(activeVotes); // const [activeVot, setActiveVot] = useState(activeVotes);
@ -44,7 +43,6 @@ const PostCardView = ({
// const [calcImgHeight, setCalcImgHeight] = useState(300); // const [calcImgHeight, setCalcImgHeight] = useState(300);
const calcImgHeight = 300; const calcImgHeight = 300;
// Component Functions // Component Functions
const _handleOnUserPress = () => { const _handleOnUserPress = () => {

View File

@ -323,6 +323,7 @@ const PostsView = ({
_onEndReachedCalledDuringMomentum = false; _onEndReachedCalledDuringMomentum = false;
}} }}
removeClippedSubviews removeClippedSubviews
//TODO: we can avoid 2 more rerenders by carefully moving these call to postsListContainer
refreshing={refreshing} refreshing={refreshing}
onRefresh={handleOnRefreshPosts} onRefresh={handleOnRefreshPosts}
onEndReachedThreshold={1} onEndReachedThreshold={1}

View File

@ -514,7 +514,6 @@ export const getPost = async (author, permlink, currentUserName = null, isPromot
try { try {
console.log('Getting post: ', author, permlink); console.log('Getting post: ', author, permlink);
const post = await client.database.call('get_content', [author, permlink]); const post = await client.database.call('get_content', [author, permlink]);
return post ? parsePost(post, currentUserName, isPromoted) : null; return post ? parsePost(post, currentUserName, isPromoted) : null;
} catch (error) { } catch (error) {
return error; return error;