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.

42 lines
1.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import {
  2. SEARCH_CHANGE,
  3. SEARCH_CLEAR,
  4. SEARCH_FETCH_SUCCESS,
  5. SEARCH_SHOW,
  6. } from 'flavours/glitch/actions/search';
  7. import { COMPOSE_MENTION, COMPOSE_REPLY } from 'flavours/glitch/actions/compose';
  8. import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
  9. const initialState = ImmutableMap({
  10. value: '',
  11. submitted: false,
  12. hidden: false,
  13. results: ImmutableMap(),
  14. });
  15. export default function search(state = initialState, action) {
  16. switch(action.type) {
  17. case SEARCH_CHANGE:
  18. return state.set('value', action.value);
  19. case SEARCH_CLEAR:
  20. return state.withMutations(map => {
  21. map.set('value', '');
  22. map.set('results', ImmutableMap());
  23. map.set('submitted', false);
  24. map.set('hidden', false);
  25. });
  26. case SEARCH_SHOW:
  27. return state.set('hidden', false);
  28. case COMPOSE_REPLY:
  29. case COMPOSE_MENTION:
  30. return state.set('hidden', true);
  31. case SEARCH_FETCH_SUCCESS:
  32. return state.set('results', ImmutableMap({
  33. accounts: ImmutableList(action.results.accounts.map(item => item.id)),
  34. statuses: ImmutableList(action.results.statuses.map(item => item.id)),
  35. hashtags: ImmutableList(action.results.hashtags),
  36. })).set('submitted', true);
  37. default:
  38. return state;
  39. }
  40. };