logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

search.js (1272B)


  1. import {
  2. SEARCH_CHANGE,
  3. SEARCH_CLEAR,
  4. SEARCH_FETCH_SUCCESS,
  5. SEARCH_SHOW,
  6. } from '../actions/search';
  7. import {
  8. COMPOSE_MENTION,
  9. COMPOSE_REPLY,
  10. COMPOSE_DIRECT,
  11. } from '../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. };