Skip to content
Snippets Groups Projects
Commit 110227ac authored by Yamagishi Kazutoshi's avatar Yamagishi Kazutoshi Committed by Eugen Rochko
Browse files

Remove status from favorites list when unfavorited (#4597)

parent f26758dc
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment