diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-01-06 13:12:11 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-01-06 13:12:11 +0100 |
commit | 70a9b0be3782122750388c24eb98b0d45e6fc6d1 (patch) | |
tree | 44b8117c35095a3a4d34d2fe6802252a51853e6a /src/client/react/reducers/search.js | |
parent | 13cac5dcd54bf87767396763226fd33719964d22 (diff) |
Save searchText in redux store
Diffstat (limited to 'src/client/react/reducers/search.js')
-rw-r--r-- | src/client/react/reducers/search.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 2a7e7a5..6027ed7 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -5,6 +5,7 @@ const DEFAULT_STATE = { results: [ 's/18562', ], + searchText: '', selectedResult: null, isExactMatch: false, }; @@ -27,13 +28,14 @@ function getSearchResults(allUsers, query) { const search = (state = DEFAULT_STATE, action) => { switch (action.type) { case 'SEARCH/INPUT_CHANGE': { - const results = getSearchResults(users.allUsers, action.typedValue); + const { searchText } = action; + const results = getSearchResults(users.allUsers, action.searchText); let selectedResult = null; let isExactMatch = false; // Is the typed value exactly the same as the first result? Then show the // appropiate icon instead of the generic search icon. - if ((results.length === 1) && (action.typedValue === users.byId[results[0]].value)) { + if ((results.length === 1) && (action.searchText === users.byId[results[0]].value)) { [selectedResult] = results; isExactMatch = true; } @@ -41,6 +43,7 @@ const search = (state = DEFAULT_STATE, action) => { return { ...state, results, + searchText, selectedResult, isExactMatch, }; |