aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-12-13 15:53:19 +0100
committerNoah Loomans <noahloomans@gmail.com>2017-12-13 15:53:19 +0100
commit503ab5c66ab524dfe36aed84a01899cd07ed2bc5 (patch)
tree68f3461d561ddc6a8e83898916aba06c193e6ffa /src/client/react/reducers
parentfe27a0819a60caaa69b059f0c86d95ab0c4084b7 (diff)
Allow selection of result using keyboard
Diffstat (limited to 'src/client/react/reducers')
-rw-r--r--src/client/react/reducers/search.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js
index f566b49..6ef0f4d 100644
--- a/src/client/react/reducers/search.js
+++ b/src/client/react/reducers/search.js
@@ -48,6 +48,34 @@ const search = (state = DEFAULT_STATE, action) => {
isExactMatch,
};
}
+
+ case 'SEARCH/CHANGE_SELECTED_RESULT': {
+ const { results, isExactMatch } = state;
+ const prevSelectedResult = state.selectedResult;
+ const prevSelectedResultIndex = results.indexOf(prevSelectedResult);
+ let nextSelectedResultIndex =
+ prevSelectedResultIndex + action.relativeChange;
+
+ if (nextSelectedResultIndex < -1) {
+ nextSelectedResultIndex = results.length - 1;
+ } else if (nextSelectedResultIndex > results.length - 1) {
+ nextSelectedResultIndex = -1;
+ }
+
+ let nextSelectedResult =
+ nextSelectedResultIndex === -1
+ ? null
+ : results[nextSelectedResultIndex];
+
+ if (isExactMatch) {
+ nextSelectedResult = prevSelectedResult;
+ }
+
+ return {
+ ...state,
+ selectedResult: nextSelectedResult,
+ };
+ }
default:
return state;
}