mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-20 11:35:29 +01:00
Remove status from favorites list when unfavorited (#4597)
This commit is contained in:
parent
f26758dc01
commit
110227ac5e
@ -3,7 +3,10 @@ import {
|
|||||||
FAVOURITED_STATUSES_EXPAND_SUCCESS,
|
FAVOURITED_STATUSES_EXPAND_SUCCESS,
|
||||||
} from '../actions/favourites';
|
} from '../actions/favourites';
|
||||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
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({
|
const initialState = ImmutableMap({
|
||||||
favourites: 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) {
|
export default function statusLists(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case FAVOURITED_STATUSES_FETCH_SUCCESS:
|
case FAVOURITED_STATUSES_FETCH_SUCCESS:
|
||||||
@ -42,6 +51,8 @@ export default function statusLists(state = initialState, action) {
|
|||||||
return appendToList(state, 'favourites', action.statuses, action.next);
|
return appendToList(state, 'favourites', action.statuses, action.next);
|
||||||
case FAVOURITE_SUCCESS:
|
case FAVOURITE_SUCCESS:
|
||||||
return prependOneToList(state, 'favourites', action.status);
|
return prependOneToList(state, 'favourites', action.status);
|
||||||
|
case UNFAVOURITE_SUCCESS:
|
||||||
|
return removeOneFromList(state, 'favourites', action.status);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user