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.

53 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, hashtags, statuses }) {
  18. return {
  19. type: SEARCH_SUGGESTIONS_READY,
  20. value,
  21. accounts,
  22. hashtags,
  23. statuses
  24. };
  25. };
  26. export function fetchSearchSuggestions(value) {
  27. return (dispatch, getState) => {
  28. if (getState().getIn(['search', 'loaded_value']) === value) {
  29. return;
  30. }
  31. api(getState).get('/api/v1/search', {
  32. params: {
  33. q: value,
  34. resolve: true,
  35. limit: 4
  36. }
  37. }).then(response => {
  38. dispatch(readySearchSuggestions(value, response.data));
  39. });
  40. };
  41. };
  42. export function resetSearch() {
  43. return {
  44. type: SEARCH_RESET
  45. };
  46. };