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.

47 lines
1.3 KiB

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