Fix optimistic zapping
This commit is contained in:
parent
0e7e49ee80
commit
d4490f4e80
|
@ -769,6 +769,7 @@ export {
|
||||||
REBLOGS_EXPAND_SUCCESS,
|
REBLOGS_EXPAND_SUCCESS,
|
||||||
REBLOGS_EXPAND_FAIL,
|
REBLOGS_EXPAND_FAIL,
|
||||||
ZAP_REQUEST,
|
ZAP_REQUEST,
|
||||||
|
ZAP_FAIL,
|
||||||
reblog,
|
reblog,
|
||||||
unreblog,
|
unreblog,
|
||||||
toggleReblog,
|
toggleReblog,
|
||||||
|
|
|
@ -30,6 +30,7 @@ import {
|
||||||
UNDISLIKE_REQUEST,
|
UNDISLIKE_REQUEST,
|
||||||
DISLIKE_FAIL,
|
DISLIKE_FAIL,
|
||||||
ZAP_REQUEST,
|
ZAP_REQUEST,
|
||||||
|
ZAP_FAIL,
|
||||||
} from '../actions/interactions';
|
} from '../actions/interactions';
|
||||||
import {
|
import {
|
||||||
STATUS_CREATE_REQUEST,
|
STATUS_CREATE_REQUEST,
|
||||||
|
@ -235,12 +236,12 @@ const simulateDislike = (
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Simulate zap of status for optimistic interactions */
|
/** 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);
|
const status = state.get(statusId);
|
||||||
if (!status) return state;
|
if (!status) return state;
|
||||||
|
|
||||||
const updatedStatus = status.merge({
|
const updatedStatus = status.merge({
|
||||||
zapped: true,
|
zapped,
|
||||||
});
|
});
|
||||||
|
|
||||||
return state.set(statusId, updatedStatus);
|
return state.set(statusId, updatedStatus);
|
||||||
|
@ -301,7 +302,9 @@ export default function statuses(state = initialState, action: AnyAction): State
|
||||||
case DISLIKE_FAIL:
|
case DISLIKE_FAIL:
|
||||||
return state.get(action.status.id) === undefined ? state : state.setIn([action.status.id, 'disliked'], false);
|
return state.get(action.status.id) === undefined ? state : state.setIn([action.status.id, 'disliked'], false);
|
||||||
case ZAP_REQUEST:
|
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:
|
case REBLOG_REQUEST:
|
||||||
return state.setIn([action.status.id, 'reblogged'], true);
|
return state.setIn([action.status.id, 'reblogged'], true);
|
||||||
case REBLOG_FAIL:
|
case REBLOG_FAIL:
|
||||||
|
|
Loading…
Reference in New Issue