Remove status from favorites list when unfavorited (#4597)

remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
Yamagishi Kazutoshi 2017-08-21 06:23:05 +09:00 committed by Eugen Rochko
parent f26758dc01
commit 110227ac5e
1 changed files with 12 additions and 1 deletions

View File

@ -3,7 +3,10 @@ import {
FAVOURITED_STATUSES_EXPAND_SUCCESS,
} from '../actions/favourites';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import { FAVOURITE_SUCCESS } from '../actions/interactions';
import {
FAVOURITE_SUCCESS,
UNFAVOURITE_SUCCESS,
} from '../actions/interactions';
const initialState = ImmutableMap({
favourites: ImmutableMap({
@ -34,6 +37,12 @@ const prependOneToList = (state, listType, status) => {
}));
};
const removeOneFromList = (state, listType, status) => {
return state.update(listType, listMap => listMap.withMutations(map => {
map.set('items', map.get('items').filter(item => item !== status.get('id')));
}));
};
export default function statusLists(state = initialState, action) {
switch(action.type) {
case FAVOURITED_STATUSES_FETCH_SUCCESS:
@ -42,6 +51,8 @@ export default function statusLists(state = initialState, action) {
return appendToList(state, 'favourites', action.statuses, action.next);
case FAVOURITE_SUCCESS:
return prependOneToList(state, 'favourites', action.status);
case UNFAVOURITE_SUCCESS:
return removeOneFromList(state, 'favourites', action.status);
default:
return state;
}