2021-08-05 06:31:29 -07:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2021-08-05 06:31:29 -07:00
|
|
|
import {
|
|
|
|
ALIASES_SUGGESTIONS_READY,
|
|
|
|
ALIASES_SUGGESTIONS_CLEAR,
|
|
|
|
ALIASES_SUGGESTIONS_CHANGE,
|
2022-02-14 12:00:41 -08:00
|
|
|
ALIASES_FETCH_SUCCESS,
|
2021-08-05 06:31:29 -07:00
|
|
|
} from '../actions/aliases';
|
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
2022-02-14 12:00:41 -08:00
|
|
|
aliases: ImmutableMap({
|
|
|
|
loaded: false,
|
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
2021-08-05 06:31:29 -07:00
|
|
|
suggestions: ImmutableMap({
|
|
|
|
value: '',
|
2021-08-08 07:17:29 -07:00
|
|
|
loaded: false,
|
2021-08-05 06:31:29 -07:00
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
export default function aliasesReducer(state = initialState, action) {
|
2022-05-11 10:40:34 -07:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case ALIASES_FETCH_SUCCESS:
|
|
|
|
return state
|
|
|
|
.setIn(['aliases', 'items'], action.value);
|
|
|
|
case ALIASES_SUGGESTIONS_CHANGE:
|
|
|
|
return state
|
|
|
|
.setIn(['suggestions', 'value'], action.value)
|
|
|
|
.setIn(['suggestions', 'loaded'], false);
|
|
|
|
case ALIASES_SUGGESTIONS_READY:
|
|
|
|
return state
|
|
|
|
.setIn(['suggestions', 'items'], ImmutableList(action.accounts.map(item => item.id)))
|
|
|
|
.setIn(['suggestions', 'loaded'], true);
|
|
|
|
case ALIASES_SUGGESTIONS_CLEAR:
|
|
|
|
return state.update('suggestions', suggestions => suggestions.withMutations(map => {
|
|
|
|
map.set('items', ImmutableList());
|
|
|
|
map.set('value', '');
|
|
|
|
map.set('loaded', false);
|
|
|
|
}));
|
|
|
|
default:
|
|
|
|
return state;
|
2021-08-05 06:31:29 -07:00
|
|
|
}
|
2021-08-11 10:22:06 -07:00
|
|
|
}
|