+ UPDATE_SAVED_QUERY: searchQuery => ({ ...state, savedQueries: searchQuery }),
+ SET_SELECTED_ITEM: item => ({ ...state, selectedItem: item }),
+ MOVE_UP: () => {
+ let selectedItem = state.selectedItem;
+ if (state.currentView === SearchView.AUTOCOMPLETE) {
+ const idx = state.searchResults.findIndex(r => r.uuid === selectedItem);
+ if (idx > 0) {
+ selectedItem = state.searchResults[idx - 1].uuid;
+ } else {
+ selectedItem = state.searchValue;
+ }
+ }
+ return {
+ ...state,
+ selectedItem
+ };
+ },
+ MOVE_DOWN: () => {
+ let selectedItem = state.selectedItem;
+ if (state.currentView === SearchView.AUTOCOMPLETE) {
+ const idx = state.searchResults.findIndex(r => r.uuid === selectedItem);
+ if (idx >= 0 && idx < state.searchResults.length - 1) {
+ selectedItem = state.searchResults[idx + 1].uuid;
+ } else if (idx < 0 && state.searchResults.length > 0) {
+ selectedItem = state.searchResults[0].uuid;
+ }
+ }
+ return {
+ ...state,
+ selectedItem
+ };
+ },