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.

51 lines
1.1 KiB

  1. import api from '../api'
  2. export const SEARCH_CHANGE = 'SEARCH_CHANGE';
  3. export const SEARCH_SUGGESTIONS_CLEAR = 'SEARCH_SUGGESTIONS_CLEAR';
  4. export const SEARCH_SUGGESTIONS_READY = 'SEARCH_SUGGESTIONS_READY';
  5. export const SEARCH_RESET = 'SEARCH_RESET';
  6. export function changeSearch(value) {
  7. return {
  8. type: SEARCH_CHANGE,
  9. value
  10. };
  11. };
  12. export function clearSearchSuggestions() {
  13. return {
  14. type: SEARCH_SUGGESTIONS_CLEAR
  15. };
  16. };
  17. export function readySearchSuggestions(value, accounts) {
  18. return {
  19. type: SEARCH_SUGGESTIONS_READY,
  20. value,
  21. accounts
  22. };
  23. };
  24. export function fetchSearchSuggestions(value) {
  25. return (dispatch, getState) => {
  26. if (getState().getIn(['search', 'loaded_value']) === value) {
  27. return;
  28. }
  29. api(getState).get('/api/v1/accounts/search', {
  30. params: {
  31. q: value,
  32. resolve: true,
  33. limit: 4
  34. }
  35. }).then(response => {
  36. dispatch(readySearchSuggestions(value, response.data));
  37. });
  38. };
  39. };
  40. export function resetSearch() {
  41. return {
  42. type: SEARCH_RESET
  43. };
  44. };