bigbuffet-rw/app/soapbox/reducers/aliases.js
marcin mikołajczak f203a4d389 WIP: Account aliases
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2021-08-05 15:31:29 +02:00

29 lines
887 B
JavaScript

import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import {
ALIASES_SUGGESTIONS_READY,
ALIASES_SUGGESTIONS_CLEAR,
ALIASES_SUGGESTIONS_CHANGE,
} from '../actions/aliases';
const initialState = ImmutableMap({
suggestions: ImmutableMap({
value: '',
items: ImmutableList(),
}),
});
export default function aliasesReducer(state = initialState, action) {
switch(action.type) {
case ALIASES_SUGGESTIONS_CHANGE:
return state.setIn(['suggestions', 'value'], action.value);
case ALIASES_SUGGESTIONS_READY:
return state.setIn(['suggestions', 'items'], ImmutableList(action.accounts.map(item => item.id)));
case ALIASES_SUGGESTIONS_CLEAR:
return state.update('suggestions', suggestions => suggestions.withMutations(map => {
map.set('items', ImmutableList());
map.set('value', '');
}));
default:
return state;
}
};