2019-07-02 08:10:25 +01:00
|
|
|
import api from '../api';
|
|
|
|
import { fetchRelationships } from './accounts';
|
2020-05-04 19:44:37 +01:00
|
|
|
import { fetchGroupsSuccess, fetchGroupRelationships } from './groups'
|
2020-10-31 23:10:59 +00:00
|
|
|
import {
|
|
|
|
importFetchedAccounts,
|
|
|
|
importFetchedStatuses,
|
|
|
|
} from './importer';
|
|
|
|
import { importLinkCards } from './links'
|
2020-08-07 05:05:02 +01:00
|
|
|
import { SEARCH_FILTERS } from '../constants'
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
export const SEARCH_CHANGE = 'SEARCH_CHANGE';
|
|
|
|
export const SEARCH_CLEAR = 'SEARCH_CLEAR';
|
|
|
|
export const SEARCH_SHOW = 'SEARCH_SHOW';
|
|
|
|
|
|
|
|
export const SEARCH_FETCH_REQUEST = 'SEARCH_FETCH_REQUEST';
|
|
|
|
export const SEARCH_FETCH_SUCCESS = 'SEARCH_FETCH_SUCCESS';
|
|
|
|
export const SEARCH_FETCH_FAIL = 'SEARCH_FETCH_FAIL';
|
|
|
|
|
2020-08-07 05:05:02 +01:00
|
|
|
export const SEARCH_FILTER_SET = 'SEARCH_FILTER_SET'
|
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const changeSearch = (value) => ({
|
|
|
|
type: SEARCH_CHANGE,
|
|
|
|
value,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const clearSearch = () => ({
|
|
|
|
type: SEARCH_CLEAR,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const submitSearch = () => (dispatch, getState) => {
|
|
|
|
const value = getState().getIn(['search', 'value'])
|
|
|
|
const onlyVerified = getState().getIn(['search', 'filter', 'onlyVerified'])
|
|
|
|
|
|
|
|
if (value.length === 0) return
|
|
|
|
|
|
|
|
dispatch(fetchSearchRequest())
|
|
|
|
|
|
|
|
api(getState).get('/api/v2/search', {
|
|
|
|
params: {
|
|
|
|
onlyVerified,
|
|
|
|
q: value,
|
|
|
|
resolve: true,
|
|
|
|
},
|
|
|
|
}).then((response) => {
|
|
|
|
if (response.data.accounts) {
|
|
|
|
dispatch(importFetchedAccounts(response.data.accounts))
|
|
|
|
dispatch(fetchRelationships(response.data.accounts.map(item => item.id)))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.statuses) {
|
|
|
|
dispatch(importFetchedStatuses(response.data.statuses))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.links) {
|
|
|
|
dispatch(importLinkCards(response.data.links))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.groups) {
|
|
|
|
dispatch(fetchGroupsSuccess(response.data.groups))
|
|
|
|
dispatch(fetchGroupRelationships(response.data.groups.map(item => item.id)))
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(fetchSearchSuccess(response.data))
|
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(fetchSearchFail(error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const fetchSearchRequest = () => ({
|
|
|
|
type: SEARCH_FETCH_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
const fetchSearchSuccess = (results) => ({
|
|
|
|
type: SEARCH_FETCH_SUCCESS,
|
|
|
|
results,
|
|
|
|
})
|
|
|
|
|
|
|
|
const fetchSearchFail = (error) => ({
|
|
|
|
type: SEARCH_FETCH_FAIL,
|
2020-12-08 04:39:13 +00:00
|
|
|
showToast: true,
|
2020-11-15 18:48:32 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const showSearch = () => ({
|
|
|
|
type: SEARCH_SHOW,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const setFilter = (path, value, shouldSubmit) => (dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: SEARCH_FILTER_SET,
|
|
|
|
path: path,
|
|
|
|
value: value,
|
|
|
|
})
|
|
|
|
if (shouldSubmit) dispatch(submitSearch())
|
2020-10-31 23:10:59 +00:00
|
|
|
}
|