Rework search
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import api from '../api'
|
||||
|
||||
export const SEARCH_CHANGE = 'SEARCH_CHANGE';
|
||||
export const SEARCH_SUGGESTIONS_CLEAR = 'SEARCH_SUGGESTIONS_CLEAR';
|
||||
export const SEARCH_SUGGESTIONS_READY = 'SEARCH_SUGGESTIONS_READY';
|
||||
export const SEARCH_RESET = 'SEARCH_RESET';
|
||||
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';
|
||||
|
||||
export function changeSearch(value) {
|
||||
return {
|
||||
@ -12,42 +15,55 @@ export function changeSearch(value) {
|
||||
};
|
||||
};
|
||||
|
||||
export function clearSearchSuggestions() {
|
||||
export function clearSearch() {
|
||||
return {
|
||||
type: SEARCH_SUGGESTIONS_CLEAR
|
||||
type: SEARCH_CLEAR
|
||||
};
|
||||
};
|
||||
|
||||
export function readySearchSuggestions(value, { accounts, hashtags, statuses }) {
|
||||
return {
|
||||
type: SEARCH_SUGGESTIONS_READY,
|
||||
value,
|
||||
accounts,
|
||||
hashtags,
|
||||
statuses
|
||||
};
|
||||
};
|
||||
|
||||
export function fetchSearchSuggestions(value) {
|
||||
export function submitSearch() {
|
||||
return (dispatch, getState) => {
|
||||
if (getState().getIn(['search', 'loaded_value']) === value) {
|
||||
return;
|
||||
}
|
||||
const value = getState().getIn(['search', 'value']);
|
||||
|
||||
dispatch(fetchSearchRequest());
|
||||
|
||||
api(getState).get('/api/v1/search', {
|
||||
params: {
|
||||
q: value,
|
||||
resolve: true,
|
||||
limit: 4
|
||||
resolve: true
|
||||
}
|
||||
}).then(response => {
|
||||
dispatch(readySearchSuggestions(value, response.data));
|
||||
dispatch(fetchSearchSuccess(response.data));
|
||||
}).catch(error => {
|
||||
dispatch(fetchSearchFail(error));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export function resetSearch() {
|
||||
export function fetchSearchRequest() {
|
||||
return {
|
||||
type: SEARCH_RESET
|
||||
type: SEARCH_FETCH_REQUEST
|
||||
};
|
||||
};
|
||||
|
||||
export function fetchSearchSuccess(results) {
|
||||
return {
|
||||
type: SEARCH_FETCH_SUCCESS,
|
||||
results,
|
||||
accounts: results.accounts,
|
||||
statuses: results.statuses
|
||||
};
|
||||
};
|
||||
|
||||
export function fetchSearchFail(error) {
|
||||
return {
|
||||
type: SEARCH_FETCH_FAIL,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
export function showSearch() {
|
||||
return {
|
||||
type: SEARCH_SHOW
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user