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';
// Search
export const SEARCH_STARTED = 'SEARCH_STARTED';
export const SEARCH_COMPLETED = 'SEARCH_COMPLETED';
export const SEARCH_CANCELLED = 'SEARCH_CANCELLED';
export const SEARCH_START = 'SEARCH_START';
export const SEARCH_SUCCESS = 'SEARCH_SUCCESS';
export const SEARCH_FAIL = 'SEARCH_FAIL';
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_FAIL = 'GET_SEARCH_SUGGESTIONS_FAIL';

View file

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

View file

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