Unliking a post updates like count on front end (#12140)

* return the new favourites_count
when unfavouriting a status

* Remove trailing whitespace

* revert changes to favourites_controller

* Decrease favourites_count through statuses reducer

* styling fix

* Fix missing trailing comma
This commit is contained in:
Nima Boscarino 2019-10-24 13:49:45 -07:00 committed by Eugen Rochko
parent 15c192ce40
commit a9530e29a2

View file

@ -3,6 +3,7 @@ import {
REBLOG_FAIL, REBLOG_FAIL,
FAVOURITE_REQUEST, FAVOURITE_REQUEST,
FAVOURITE_FAIL, FAVOURITE_FAIL,
UNFAVOURITE_SUCCESS,
} from '../actions/interactions'; } from '../actions/interactions';
import { import {
STATUS_MUTE_SUCCESS, STATUS_MUTE_SUCCESS,
@ -37,6 +38,9 @@ export default function statuses(state = initialState, action) {
return importStatuses(state, action.statuses); return importStatuses(state, action.statuses);
case FAVOURITE_REQUEST: case FAVOURITE_REQUEST:
return state.setIn([action.status.get('id'), 'favourited'], true); return state.setIn([action.status.get('id'), 'favourited'], true);
case UNFAVOURITE_SUCCESS:
const favouritesCount = action.status.get('favourites_count');
return state.setIn([action.status.get('id'), 'favourites_count'], favouritesCount - 1);
case FAVOURITE_FAIL: case FAVOURITE_FAIL:
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false); return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false);
case REBLOG_REQUEST: case REBLOG_REQUEST: