From d4490f4e80c4efe9c2a42c2163b93f4208b7daf7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Jan 2024 16:12:30 -0600 Subject: [PATCH] Fix optimistic zapping --- src/actions/interactions.ts | 1 + src/reducers/statuses.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/actions/interactions.ts b/src/actions/interactions.ts index 58a92f6cc..cab5cd740 100644 --- a/src/actions/interactions.ts +++ b/src/actions/interactions.ts @@ -769,6 +769,7 @@ export { REBLOGS_EXPAND_SUCCESS, REBLOGS_EXPAND_FAIL, ZAP_REQUEST, + ZAP_FAIL, reblog, unreblog, toggleReblog, diff --git a/src/reducers/statuses.ts b/src/reducers/statuses.ts index 8d336ce6c..0b94d228a 100644 --- a/src/reducers/statuses.ts +++ b/src/reducers/statuses.ts @@ -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: