Optimistic zap
This commit is contained in:
parent
9cad54c97c
commit
d20d08bc8f
2 changed files with 16 additions and 0 deletions
|
@ -768,6 +768,7 @@ export {
|
|||
FAVOURITES_EXPAND_FAIL,
|
||||
REBLOGS_EXPAND_SUCCESS,
|
||||
REBLOGS_EXPAND_FAIL,
|
||||
ZAP_REQUEST,
|
||||
reblog,
|
||||
unreblog,
|
||||
toggleReblog,
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue