From c93f459113f976c808ab4b07f784c5125cf6548c Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 5 Jan 2018 02:26:39 -0500 Subject: [PATCH] update search action names to proper naming conventions --- src/renderer/constants/action_types.js | 8 ++++---- src/renderer/redux/actions/search.js | 22 +++++++++++----------- src/renderer/redux/reducers/search.js | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/renderer/constants/action_types.js b/src/renderer/constants/action_types.js index c1e6fc525..9a8c57c7f 100644 --- a/src/renderer/constants/action_types.js +++ b/src/renderer/constants/action_types.js @@ -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'; diff --git a/src/renderer/redux/actions/search.js b/src/renderer/redux/actions/search.js index fc41a65dd..d5294b54c 100644 --- a/src/renderer/redux/actions/search.js +++ b/src/renderer/redux/actions/search.js @@ -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, diff --git a/src/renderer/redux/reducers/search.js b/src/renderer/redux/reducers/search.js index b6474bfe0..3a8330b93 100644 --- a/src/renderer/redux/reducers/search.js +++ b/src/renderer/redux/reducers/search.js @@ -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: [],