29 lines
887 B
JavaScript
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;
|
|
}
|
|
};
|