Fix optimistic zapping

This commit is contained in:
Alex Gleason 2024-01-22 16:12:30 -06:00
parent 0e7e49ee80
commit d4490f4e80
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 7 additions and 3 deletions

View file

@ -769,6 +769,7 @@ export {
REBLOGS_EXPAND_SUCCESS,
REBLOGS_EXPAND_FAIL,
ZAP_REQUEST,
ZAP_FAIL,
reblog,
unreblog,
toggleReblog,

View file

@ -30,6 +30,7 @@ import {
UNDISLIKE_REQUEST,
DISLIKE_FAIL,
ZAP_REQUEST,
ZAP_FAIL,
} from '../actions/interactions';
import {
STATUS_CREATE_REQUEST,
@ -235,12 +236,12 @@ const simulateDislike = (
};
/** Simulate zap of status for optimistic interactions */
const simulateZap = (state: State, statusId: string): State => {
const simulateZap = (state: State, statusId: string, zapped: boolean): State => {
const status = state.get(statusId);
if (!status) return state;
const updatedStatus = status.merge({
zapped: true,
zapped,
});
return state.set(statusId, updatedStatus);
@ -301,7 +302,9 @@ export default function statuses(state = initialState, action: AnyAction): State
case DISLIKE_FAIL:
return state.get(action.status.id) === undefined ? state : state.setIn([action.status.id, 'disliked'], false);
case ZAP_REQUEST:
return simulateZap(state, action.status.id);
return simulateZap(state, action.status.id, true);
case ZAP_FAIL:
return simulateZap(state, action.status.id, false);
case REBLOG_REQUEST:
return state.setIn([action.status.id, 'reblogged'], true);
case REBLOG_FAIL: