aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/store/reducers.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-06-28 16:03:46 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-06-28 16:03:46 +0200
commit41620ceb096a4c3d94bb83cf9a56077939d89a2c (patch)
tree8a4bf7ea74d2f16d6d77a5e8cc57c9a9a2fc5c80 /src/client/react/store/reducers.js
parente741808bb640abdd7303be7ba0cf519f68b2977f (diff)
Refactor search
Diffstat (limited to 'src/client/react/store/reducers.js')
-rw-r--r--src/client/react/store/reducers.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/client/react/store/reducers.js b/src/client/react/store/reducers.js
index c2ee7e9..3425de0 100644
--- a/src/client/react/store/reducers.js
+++ b/src/client/react/store/reducers.js
@@ -74,30 +74,31 @@ function reducer(state = DEFAULT_STATE, action) {
};
}
- case 'SEARCH/INPUT_CHANGE':
+ case 'SEARCH/INPUT_CHANGE': {
+ const results = getSearchResults(action.searchText);
+
return {
...state,
search: {
- results: getSearchResults(action.searchText),
+ results,
text: action.searchText,
- selected: null,
+ selected: results.length > 0 ? results[0] : null,
},
};
+ }
case 'SEARCH/CHANGE_SELECTED_RESULT': {
const prevSelectedResult = state.search.selected;
const prevSelectedResultIndex = state.search.results.indexOf(prevSelectedResult);
let nextSelectedResultIndex = prevSelectedResultIndex + action.relativeChange;
- if (nextSelectedResultIndex < -1) {
+ if (nextSelectedResultIndex < 0) {
nextSelectedResultIndex = state.search.results.length - 1;
} else if (nextSelectedResultIndex > state.search.results.length - 1) {
- nextSelectedResultIndex = -1;
+ nextSelectedResultIndex = 0;
}
- const nextSelectedResult = nextSelectedResultIndex === -1
- ? null
- : state.search.results[nextSelectedResultIndex];
+ const nextSelectedResult = state.search.results[nextSelectedResultIndex];
return {
...state,