From d20d08bc8fdfde7b63578e37d45b5f9d6aa74327 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Jan 2024 18:56:18 -0600 Subject: [PATCH] Optimistic zap --- src/actions/interactions.ts | 1 + src/reducers/statuses.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/actions/interactions.ts b/src/actions/interactions.ts index ddd29c2c7..58a92f6cc 100644 --- a/src/actions/interactions.ts +++ b/src/actions/interactions.ts @@ -768,6 +768,7 @@ export { FAVOURITES_EXPAND_FAIL, REBLOGS_EXPAND_SUCCESS, REBLOGS_EXPAND_FAIL, + ZAP_REQUEST, reblog, unreblog, toggleReblog, diff --git a/src/reducers/statuses.ts b/src/reducers/statuses.ts index 37d7ec2ad..8d336ce6c 100644 --- a/src/reducers/statuses.ts +++ b/src/reducers/statuses.ts @@ -29,6 +29,7 @@ import { DISLIKE_REQUEST, UNDISLIKE_REQUEST, DISLIKE_FAIL, + ZAP_REQUEST, } from '../actions/interactions'; import { STATUS_CREATE_REQUEST, @@ -233,6 +234,18 @@ const simulateDislike = ( return state.set(statusId, updatedStatus); }; +/** Simulate zap of status for optimistic interactions */ +const simulateZap = (state: State, statusId: string): State => { + const status = state.get(statusId); + if (!status) return state; + + const updatedStatus = status.merge({ + zapped: true, + }); + + return state.set(statusId, updatedStatus); +}; + interface Translation { content: string; detected_source_language: string; @@ -287,6 +300,8 @@ export default function statuses(state = initialState, action: AnyAction): State return state.get(action.status.id) === undefined ? state : state.setIn([action.status.id, 'favourited'], false); 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); case REBLOG_REQUEST: return state.setIn([action.status.id, 'reblogged'], true); case REBLOG_FAIL: