diff options
author | Yamagishi Kazutoshi <ykzts@desire.sh> | 2017-08-21 06:23:05 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-08-20 23:23:05 +0200 |
commit | 110227ac5e77c2be51ef8be4bca614d357c0eb13 (patch) | |
tree | a011128ef90b229b7b4c0e84cda4bbf3457764e7 | |
parent | f26758dc019a24cd7e87078e2a19350d0a2d083c (diff) |
Remove status from favorites list when unfavorited (#4597)
-rw-r--r-- | app/javascript/mastodon/reducers/status_lists.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/app/javascript/mastodon/reducers/status_lists.js b/app/javascript/mastodon/reducers/status_lists.js index 580cc17d2..2ce27a454 100644 --- a/app/javascript/mastodon/reducers/status_lists.js +++ b/app/javascript/mastodon/reducers/status_lists.js @@ -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; } |