You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
891 B

  1. import {
  2. SUGGESTIONS_FETCH_REQUEST,
  3. SUGGESTIONS_FETCH_SUCCESS,
  4. SUGGESTIONS_FETCH_FAIL,
  5. SUGGESTIONS_DISMISS,
  6. } from '../actions/suggestions';
  7. import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
  8. const initialState = ImmutableMap({
  9. items: ImmutableList(),
  10. isLoading: false,
  11. });
  12. export default function suggestionsReducer(state = initialState, action) {
  13. switch(action.type) {
  14. case SUGGESTIONS_FETCH_REQUEST:
  15. return state.set('isLoading', true);
  16. case SUGGESTIONS_FETCH_SUCCESS:
  17. return state.withMutations(map => {
  18. map.set('items', fromJS(action.accounts.map(x => x.id)));
  19. map.set('isLoading', false);
  20. });
  21. case SUGGESTIONS_FETCH_FAIL:
  22. return state.set('isLoading', false);
  23. case SUGGESTIONS_DISMISS:
  24. return state.update('items', list => list.filterNot(id => id === action.id));
  25. default:
  26. return state;
  27. }
  28. };