aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers
diff options
context:
space:
mode:
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;
}