mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 08:55:14 +03:00
unvote cache support
This commit is contained in:
parent
be96429431
commit
3be323bf98
@ -204,7 +204,7 @@ const UpvotePopover = forwardRef(({ }: Props, ref) => {
|
||||
return;
|
||||
}
|
||||
setIsVoted(!!sliderValue);
|
||||
_updateVoteCache(_author, _permlink, amount, false, !!sliderValue ? CacheStatus.DELETED : CacheStatus.PUBLISHED);
|
||||
_updateVoteCache(_author, _permlink, amount, false, !!sliderValue ? CacheStatus.PUBLISHED : CacheStatus.DELETED);
|
||||
})
|
||||
.catch((err) => {
|
||||
_updateVoteCache(_author, _permlink, amount, false, CacheStatus.FAILED);
|
||||
@ -267,7 +267,7 @@ const UpvotePopover = forwardRef(({ }: Props, ref) => {
|
||||
transactionId: response.id,
|
||||
});
|
||||
setIsVoted(!!sliderValue);
|
||||
_updateVoteCache(_author, _permlink, amount, true, !!sliderValue ? CacheStatus.DELETED : CacheStatus.PUBLISHED);
|
||||
_updateVoteCache(_author, _permlink, amount, true, !!sliderValue ? CacheStatus.PUBLISHED : CacheStatus.DELETED);
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch(
|
||||
|
@ -318,12 +318,12 @@ export const injectPostCache = (commentsMap, cachedComments, cachedVotes, lastCa
|
||||
|
||||
|
||||
export const injectVoteCache = (post, voteCache) => {
|
||||
if (
|
||||
voteCache &&
|
||||
(voteCache.status !== CacheStatus.FAILED || voteCache.status !== CacheStatus.DELETED)
|
||||
) {
|
||||
if (voteCache && voteCache.status !== CacheStatus.FAILED) {
|
||||
|
||||
const _voteIndex = post.active_votes.findIndex((i) => i.voter === voteCache.voter);
|
||||
if (_voteIndex < 0) {
|
||||
|
||||
//if vote do not already exist
|
||||
if (_voteIndex < 0 && voteCache.status !== CacheStatus.DELETED ) {
|
||||
post.total_payout += voteCache.amount * (voteCache.isDownvote ? -1 : 1);
|
||||
post.active_votes = [
|
||||
...post.active_votes,
|
||||
@ -332,8 +332,14 @@ export const injectVoteCache = (post, voteCache) => {
|
||||
rshares: voteCache.isDownvote ? -1000 : 1000,
|
||||
},
|
||||
];
|
||||
} else {
|
||||
post.active_votes[_voteIndex].rshares = voteCache.isDownvote ? -1000 : 1000;
|
||||
}
|
||||
|
||||
//if vote already exist
|
||||
else {
|
||||
post.active_votes[_voteIndex].rshares = voteCache.status === CacheStatus.DELETED
|
||||
? 0
|
||||
: voteCache.isDownvote
|
||||
? -1000 : 1000;
|
||||
post.active_votes = [...post.active_votes];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user