mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 19:31:54 +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,
|
||||
setImageHeight,
|
||||
}) => {
|
||||
const [_content, setContent] = useState(content);
|
||||
const [reblogs, setReblogs] = useState([]);
|
||||
const [activeVotes, setActiveVotes] = useState(get(_content, 'active_votes', []));
|
||||
|
||||
//NOTE: potentially unnessacry fetch
|
||||
// useEffect(() => {
|
||||
// if (isRefresh) {
|
||||
// _fetchPost();
|
||||
// }
|
||||
// }, [isRefresh]);
|
||||
const activeVotes = get(content, 'active_votes', []);
|
||||
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
@ -59,24 +51,24 @@ const PostCardContainer = ({
|
||||
}
|
||||
};
|
||||
|
||||
if (_content) {
|
||||
fetchData(_content);
|
||||
if (content) {
|
||||
fetchData(content);
|
||||
}
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [_content]);
|
||||
}, [content]);
|
||||
|
||||
const _handleOnUserPress = () => {
|
||||
if (_content && get(currentAccount, 'name') !== get(_content, 'author')) {
|
||||
if (content && get(currentAccount, 'name') !== get(content, 'author')) {
|
||||
navigation.navigate({
|
||||
routeName: ROUTES.SCREENS.PROFILE,
|
||||
params: {
|
||||
username: get(_content, 'author'),
|
||||
reputation: get(_content, 'author_reputation'),
|
||||
username: get(content, 'author'),
|
||||
reputation: get(content, 'author_reputation'),
|
||||
},
|
||||
key: get(_content, 'author'),
|
||||
key: get(content, 'author'),
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -98,9 +90,9 @@ const PostCardContainer = ({
|
||||
routeName: ROUTES.SCREENS.VOTERS,
|
||||
params: {
|
||||
activeVotes,
|
||||
content: _content,
|
||||
content: content,
|
||||
},
|
||||
key: get(_content, 'permlink'),
|
||||
key: get(content, 'permlink'),
|
||||
});
|
||||
};
|
||||
|
||||
@ -110,33 +102,17 @@ const PostCardContainer = ({
|
||||
params: {
|
||||
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 (
|
||||
<PostCardView
|
||||
handleOnUserPress={_handleOnUserPress}
|
||||
handleOnContentPress={_handleOnContentPress}
|
||||
handleOnVotersPress={_handleOnVotersPress}
|
||||
handleOnReblogsPress={_handleOnReblogsPress}
|
||||
fetchPost={_fetchPost}
|
||||
content={_content || content}
|
||||
content={content}
|
||||
isHideImage={isHideImage}
|
||||
isNsfwPost={nsfw || '1'}
|
||||
reblogs={reblogs}
|
||||
|
@ -40,11 +40,15 @@ const PostCardView = ({
|
||||
imageHeight,
|
||||
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);
|
||||
|
||||
// Component Functions
|
||||
useEffect(() => {
|
||||
setActiveVotesCount(activeVotes ? activeVotes.length : 0);
|
||||
}, [activeVotes]);
|
||||
|
||||
// Component Functions
|
||||
const _handleOnUserPress = () => {
|
||||
if (handleOnUserPress) {
|
||||
handleOnUserPress();
|
||||
@ -66,6 +70,7 @@ const PostCardView = ({
|
||||
};
|
||||
|
||||
const _handleIncrementVoteCount = () => {
|
||||
//fake increment vote using based on local change
|
||||
setActiveVotesCount(activeVotesCount + 1);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user