logo

mastofe

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

search.js (1792B)


  1. import api from '../api';
  2. import { fetchRelationships } from './accounts';
  3. import { importFetchedAccounts, importFetchedStatuses } from './importer';
  4. export const SEARCH_CHANGE = 'SEARCH_CHANGE';
  5. export const SEARCH_CLEAR = 'SEARCH_CLEAR';
  6. export const SEARCH_SHOW = 'SEARCH_SHOW';
  7. export const SEARCH_FETCH_REQUEST = 'SEARCH_FETCH_REQUEST';
  8. export const SEARCH_FETCH_SUCCESS = 'SEARCH_FETCH_SUCCESS';
  9. export const SEARCH_FETCH_FAIL = 'SEARCH_FETCH_FAIL';
  10. export function changeSearch(value) {
  11. return {
  12. type: SEARCH_CHANGE,
  13. value,
  14. };
  15. };
  16. export function clearSearch() {
  17. return {
  18. type: SEARCH_CLEAR,
  19. };
  20. };
  21. export function submitSearch() {
  22. return (dispatch, getState) => {
  23. const value = getState().getIn(['search', 'value']);
  24. if (value.length === 0) {
  25. return;
  26. }
  27. dispatch(fetchSearchRequest());
  28. api(getState).get('/api/v1/search', {
  29. params: {
  30. q: value,
  31. resolve: true,
  32. },
  33. }).then(response => {
  34. if (response.data.accounts) {
  35. dispatch(importFetchedAccounts(response.data.accounts));
  36. }
  37. if (response.data.statuses) {
  38. dispatch(importFetchedStatuses(response.data.statuses));
  39. }
  40. dispatch(fetchSearchSuccess(response.data));
  41. dispatch(fetchRelationships(response.data.accounts.map(item => item.id)));
  42. }).catch(error => {
  43. dispatch(fetchSearchFail(error));
  44. });
  45. };
  46. };
  47. export function fetchSearchRequest() {
  48. return {
  49. type: SEARCH_FETCH_REQUEST,
  50. };
  51. };
  52. export function fetchSearchSuccess(results) {
  53. return {
  54. type: SEARCH_FETCH_SUCCESS,
  55. results,
  56. };
  57. };
  58. export function fetchSearchFail(error) {
  59. return {
  60. type: SEARCH_FETCH_FAIL,
  61. error,
  62. };
  63. };
  64. export function showSearch() {
  65. return {
  66. type: SEARCH_SHOW,
  67. };
  68. };