update search action names to proper naming conventions

This commit is contained in:
Sean Yesmunt 2018-01-05 02:26:39 -05:00
parent 92482ee916
commit c93f459113
3 changed files with 19 additions and 19 deletions

View file

@ -88,11 +88,11 @@ export const FETCH_AVAILABILITY_COMPLETED = 'FETCH_AVAILABILITY_COMPLETED';
export const FILE_DELETE = 'FILE_DELETE'; export const FILE_DELETE = 'FILE_DELETE';
// Search // Search
export const SEARCH_STARTED = 'SEARCH_STARTED'; export const SEARCH_START = 'SEARCH_START';
export const SEARCH_COMPLETED = 'SEARCH_COMPLETED'; export const SEARCH_SUCCESS = 'SEARCH_SUCCESS';
export const SEARCH_CANCELLED = 'SEARCH_CANCELLED'; export const SEARCH_FAIL = 'SEARCH_FAIL';
export const UPDATE_SEARCH_QUERY = 'UPDATE_SEARCH_QUERY'; export const UPDATE_SEARCH_QUERY = 'UPDATE_SEARCH_QUERY';
export const GET_SEARCH_SUGGESTIONS_START = 'GET_SEARCH_SUGGESTIONS_START'; export const SEARCH_SUGGESTIONS_START = 'SEARCH_SUGGESTIONS_START';
export const GET_SEARCH_SUGGESTIONS_SUCCESS = 'GET_SEARCH_SUGGESTIONS_SUCCESS'; export const GET_SEARCH_SUGGESTIONS_SUCCESS = 'GET_SEARCH_SUGGESTIONS_SUCCESS';
export const GET_SEARCH_SUGGESTIONS_FAIL = 'GET_SEARCH_SUGGESTIONS_FAIL'; export const GET_SEARCH_SUGGESTIONS_FAIL = 'GET_SEARCH_SUGGESTIONS_FAIL';

View file

@ -6,10 +6,10 @@ import { selectCurrentPage } from 'redux/selectors/navigation';
import batchActions from 'util/batchActions'; import batchActions from 'util/batchActions';
// TODO: this should be in a util // TODO: this should be in a util
const handleResponse = response => const handleSearchApiResponse = searchResponse =>
response.status === 200 searchResponse.status === 200
? Promise.resolve(response.json()) ? Promise.resolve(searchResponse.json())
: Promise.reject(new Error(response.statusText)); : Promise.reject(new Error(searchResponse.statusText));
export const doSearch = rawQuery => (dispatch, getState) => { export const doSearch = rawQuery => (dispatch, getState) => {
const state = getState(); const state = getState();
@ -19,13 +19,13 @@ export const doSearch = rawQuery => (dispatch, getState) => {
if (!query) { if (!query) {
dispatch({ dispatch({
type: ACTIONS.SEARCH_CANCELLED, type: ACTIONS.SEARCH_FAIL,
}); });
return; return;
} }
dispatch({ dispatch({
type: ACTIONS.SEARCH_STARTED, type: ACTIONS.SEARCH_START,
data: { query }, data: { query },
}); });
@ -33,7 +33,7 @@ export const doSearch = rawQuery => (dispatch, getState) => {
dispatch(doNavigate('search', { query })); dispatch(doNavigate('search', { query }));
} else { } else {
fetch(`https://lighthouse.lbry.io/search?s=${query}`) fetch(`https://lighthouse.lbry.io/search?s=${query}`)
.then(handleResponse) .then(handleSearchApiResponse)
.then(data => { .then(data => {
const uris = []; const uris = [];
const actions = []; const actions = [];
@ -48,7 +48,7 @@ export const doSearch = rawQuery => (dispatch, getState) => {
}); });
actions.push({ actions.push({
type: ACTIONS.SEARCH_COMPLETED, type: ACTIONS.SEARCH_SUCCESS,
data: { data: {
query, query,
uris, uris,
@ -58,7 +58,7 @@ export const doSearch = rawQuery => (dispatch, getState) => {
}) })
.catch(() => { .catch(() => {
dispatch({ dispatch({
type: ACTIONS.SEARCH_CANCELLED, type: ACTIONS.SEARCH_FAIL,
}); });
}); });
} }
@ -70,7 +70,7 @@ export const updateSearchQuery = searchQuery => ({
}); });
export const getSearchSuggestions = value => dispatch => { export const getSearchSuggestions = value => dispatch => {
dispatch({ type: ACTIONS.GET_SEARCH_SUGGESTIONS_START }); dispatch({ type: ACTIONS.SEARCH_SUGGESTIONS_START });
if (!value) { if (!value) {
dispatch({ dispatch({
type: ACTIONS.GET_SEARCH_SUGGESTIONS_SUCCESS, type: ACTIONS.GET_SEARCH_SUGGESTIONS_SUCCESS,
@ -87,7 +87,7 @@ export const getSearchSuggestions = value => dispatch => {
// need to handle spaces in the query? // need to handle spaces in the query?
fetch(`https://lighthouse.lbry.io/autocomplete?s=${searchValue}`) fetch(`https://lighthouse.lbry.io/autocomplete?s=${searchValue}`)
.then(handleResponse) .then(handleSearchApiResponse)
.then(suggestions => { .then(suggestions => {
const formattedSuggestions = suggestions.slice(0, 5).map(suggestion => ({ const formattedSuggestions = suggestions.slice(0, 5).map(suggestion => ({
label: suggestion, label: suggestion,

View file

@ -20,11 +20,11 @@ const defaultState = {
export default handleActions( export default handleActions(
{ {
[ACTIONS.SEARCH_STARTED]: (state: SearchState): SearchState => ({ [ACTIONS.SEARCH_START]: (state: SearchState): SearchState => ({
...state, ...state,
searching: true, searching: true,
}), }),
[ACTIONS.SEARCH_COMPLETED]: (state: SearchState, action): SearchState => { [ACTIONS.SEARCH_SUCCESS]: (state: SearchState, action): SearchState => {
const { query, uris } = action.data; const { query, uris } = action.data;
return { return {
@ -34,7 +34,7 @@ export default handleActions(
}; };
}, },
[ACTIONS.SEARCH_CANCELLED]: (state: SearchState): SearchState => ({ [ACTIONS.SEARCH_FAIL]: (state: SearchState): SearchState => ({
...state, ...state,
searching: false, searching: false,
}), }),
@ -46,7 +46,7 @@ export default handleActions(
isActive: true, isActive: true,
}), }),
[ACTIONS.GET_SEARCH_SUGGESTIONS_START]: (state: SearchState): SearchState => ({ [ACTIONS.SEARCH_SUGGESTIONS_START]: (state: SearchState): SearchState => ({
...state, ...state,
searchingForSuggestions: true, searchingForSuggestions: true,
suggestions: [], suggestions: [],