forked from treehouse/mastodon
Add favourited toot to favourites column (#4562)
* Add faved toot to faves column * renamed append to prepend for claritysignup-info-prompt
parent
820099813f
commit
b1c8a702a4
|
@ -3,6 +3,7 @@ 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';
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
favourites: ImmutableMap({
|
favourites: ImmutableMap({
|
||||||
|
@ -27,12 +28,20 @@ const appendToList = (state, listType, statuses, next) => {
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const prependOneToList = (state, listType, status) => {
|
||||||
|
return state.update(listType, listMap => listMap.withMutations(map => {
|
||||||
|
map.set('items', map.get('items').unshift(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:
|
||||||
return normalizeList(state, 'favourites', action.statuses, action.next);
|
return normalizeList(state, 'favourites', action.statuses, action.next);
|
||||||
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
|
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
|
||||||
return appendToList(state, 'favourites', action.statuses, action.next);
|
return appendToList(state, 'favourites', action.statuses, action.next);
|
||||||
|
case FAVOURITE_SUCCESS:
|
||||||
|
return prependOneToList(state, 'favourites', action.status);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue