mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 03:42:10 +03:00
Merge pull request #1884 from ecency/upvote-refresh-fix
Upvote refresh fix
This commit is contained in:
commit
ea22d79553
@ -30,16 +30,8 @@ const PostCardContainer = ({
|
|||||||
imageHeight,
|
imageHeight,
|
||||||
setImageHeight,
|
setImageHeight,
|
||||||
}) => {
|
}) => {
|
||||||
const [_content, setContent] = useState(content);
|
|
||||||
const [reblogs, setReblogs] = useState([]);
|
const [reblogs, setReblogs] = useState([]);
|
||||||
const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', []));
|
const activeVotes = get(content, 'active_votes', []);
|
||||||
|
|
||||||
//NOTE: potentially unnessacry fetch
|
|
||||||
// useEffect(() => {
|
|
||||||
// if (isRefresh) {
|
|
||||||
// _fetchPost();
|
|
||||||
// }
|
|
||||||
// }, [isRefresh]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isCancelled = false;
|
let isCancelled = false;
|
||||||
@ -59,24 +51,24 @@ const PostCardContainer = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_content) {
|
if (content) {
|
||||||
fetchData(_content);
|
fetchData(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isCancelled = true;
|
isCancelled = true;
|
||||||
};
|
};
|
||||||
}, [_content]);
|
}, [content]);
|
||||||
|
|
||||||
const _handleOnUserPress = () => {
|
const _handleOnUserPress = () => {
|
||||||
if (_content && get(currentAccount, 'name') !== get(_content, 'author')) {
|
if (content && get(currentAccount, 'name') !== get(content, 'author')) {
|
||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
routeName: ROUTES.SCREENS.PROFILE,
|
routeName: ROUTES.SCREENS.PROFILE,
|
||||||
params: {
|
params: {
|
||||||
username: get(_content, 'author'),
|
username: get(content, 'author'),
|
||||||
reputation: get(_content, 'author_reputation'),
|
reputation: get(content, 'author_reputation'),
|
||||||
},
|
},
|
||||||
key: get(_content, 'author'),
|
key: get(content, 'author'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -98,9 +90,9 @@ const PostCardContainer = ({
|
|||||||
routeName: ROUTES.SCREENS.VOTERS,
|
routeName: ROUTES.SCREENS.VOTERS,
|
||||||
params: {
|
params: {
|
||||||
activeVotes,
|
activeVotes,
|
||||||
content: _content,
|
content: content,
|
||||||
},
|
},
|
||||||
key: get(_content, 'permlink'),
|
key: get(content, 'permlink'),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -110,33 +102,17 @@ const PostCardContainer = ({
|
|||||||
params: {
|
params: {
|
||||||
reblogs,
|
reblogs,
|
||||||
},
|
},
|
||||||
key: get(_content, 'permlink', get(_content, 'author', '')),
|
key: get(content, 'permlink', get(content, 'author', '')),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const _fetchPost = async () => {
|
|
||||||
await getPost(
|
|
||||||
get(_content, 'author'),
|
|
||||||
get(_content, 'permlink'),
|
|
||||||
get(currentAccount, 'username'),
|
|
||||||
)
|
|
||||||
.then((result) => {
|
|
||||||
if (result) {
|
|
||||||
setContent(result);
|
|
||||||
setActiveVotes(get(result, 'active_votes', []));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PostCardView
|
<PostCardView
|
||||||
handleOnUserPress={_handleOnUserPress}
|
handleOnUserPress={_handleOnUserPress}
|
||||||
handleOnContentPress={_handleOnContentPress}
|
handleOnContentPress={_handleOnContentPress}
|
||||||
handleOnVotersPress={_handleOnVotersPress}
|
handleOnVotersPress={_handleOnVotersPress}
|
||||||
handleOnReblogsPress={_handleOnReblogsPress}
|
handleOnReblogsPress={_handleOnReblogsPress}
|
||||||
fetchPost={_fetchPost}
|
content={content}
|
||||||
content={_content || content}
|
|
||||||
isHideImage={isHideImage}
|
isHideImage={isHideImage}
|
||||||
isNsfwPost={nsfw || '1'}
|
isNsfwPost={nsfw || '1'}
|
||||||
reblogs={reblogs}
|
reblogs={reblogs}
|
||||||
|
@ -40,11 +40,15 @@ const PostCardView = ({
|
|||||||
imageHeight,
|
imageHeight,
|
||||||
setImageHeight,
|
setImageHeight,
|
||||||
}) => {
|
}) => {
|
||||||
const [activeVotesCount, setActiveVotesCount] = useState(activeVotes.length || 0);
|
//local state to manage fake upvote if available
|
||||||
|
const [activeVotesCount, setActiveVotesCount] = useState(0);
|
||||||
const [calcImgHeight, setCalcImgHeight] = useState(imageHeight || 300);
|
const [calcImgHeight, setCalcImgHeight] = useState(imageHeight || 300);
|
||||||
|
|
||||||
// Component Functions
|
useEffect(() => {
|
||||||
|
setActiveVotesCount(activeVotes ? activeVotes.length : 0);
|
||||||
|
}, [activeVotes]);
|
||||||
|
|
||||||
|
// Component Functions
|
||||||
const _handleOnUserPress = () => {
|
const _handleOnUserPress = () => {
|
||||||
if (handleOnUserPress) {
|
if (handleOnUserPress) {
|
||||||
handleOnUserPress();
|
handleOnUserPress();
|
||||||
@ -66,6 +70,7 @@ const PostCardView = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const _handleIncrementVoteCount = () => {
|
const _handleIncrementVoteCount = () => {
|
||||||
|
//fake increment vote using based on local change
|
||||||
setActiveVotesCount(activeVotesCount + 1);
|
setActiveVotesCount(activeVotesCount + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user