Handle reblogs counts
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
838ace63d9
commit
42aa17b39e
2 changed files with 11 additions and 6 deletions
|
@ -110,8 +110,8 @@ const unreblog = (status: Pick<Status, 'id'>) =>
|
|||
|
||||
dispatch(unreblogRequest(status.id));
|
||||
|
||||
return getClient(getState()).statuses.unreblogStatus(status.id).then(() => {
|
||||
dispatch(unreblogSuccess(status.id));
|
||||
return getClient(getState()).statuses.unreblogStatus(status.id).then((status) => {
|
||||
dispatch(unreblogSuccess(status));
|
||||
}).catch(error => {
|
||||
dispatch(unreblogFail(status.id, error));
|
||||
});
|
||||
|
@ -148,9 +148,10 @@ const unreblogRequest = (statusId: string) => ({
|
|||
statusId,
|
||||
});
|
||||
|
||||
const unreblogSuccess = (statusId: string) => ({
|
||||
const unreblogSuccess = (status: Status) => ({
|
||||
type: UNREBLOG_SUCCESS,
|
||||
statusId,
|
||||
status,
|
||||
statusId: status.id,
|
||||
});
|
||||
|
||||
const unreblogFail = (statusId: string, error: unknown) => ({
|
||||
|
|
|
@ -217,11 +217,15 @@ const statuses = (state = initialState, action: AnyAction): State => {
|
|||
case DISLIKE_FAIL:
|
||||
return state.get(action.statusId) === undefined ? state : state.setIn([action.statusId, 'disliked'], false);
|
||||
case REBLOG_REQUEST:
|
||||
return state.setIn([action.statusId, 'reblogged'], true);
|
||||
return state
|
||||
.updateIn([action.statusId, 'reblogs_count'], 0, (count) => typeof count === 'number' ? count + 1 : 1)
|
||||
.setIn([action.statusId, 'reblogged'], true);
|
||||
case REBLOG_FAIL:
|
||||
return state.get(action.statusId) === undefined ? state : state.setIn([action.statusId, 'reblogged'], false);
|
||||
case UNREBLOG_REQUEST:
|
||||
return state.setIn([action.statusId, 'reblogged'], false);
|
||||
return state
|
||||
.updateIn([action.statusId, 'reblogs_count'], 0, (count) => typeof count === 'number' ? Math.max(0, count - 1) : 0)
|
||||
.setIn([action.statusId, 'reblogged'], false);
|
||||
case UNREBLOG_FAIL:
|
||||
return state.get(action.statusId) === undefined ? state : state.setIn([action.statusId, 'reblogged'], true);
|
||||
case STATUS_MUTE_SUCCESS:
|
||||
|
|
Loading…
Reference in a new issue