aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers/search.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/reducers/search.js')
-rw-r--r--src/client/react/reducers/search.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js
index 4e2032d..72fa469 100644
--- a/src/client/react/reducers/search.js
+++ b/src/client/react/reducers/search.js
@@ -1,21 +1,36 @@
+/* global USERS */
+import fuzzy from 'fuzzy';
+
const DEFAULT_STATE = {
searchInput: '',
- searchResults: [],
+ searchResults: [
+ { type: 's', value: '18561' },
+ ],
hasFocus: false,
};
+function getSearchResults(query) {
+ if (query.trim() === '') {
+ return [];
+ }
+
+ const allResults = fuzzy.filter(query, USERS, {
+ extract: user => user.value,
+ });
+
+ const firstResults = allResults.splice(0, 4);
+ const users = firstResults.map(result => result.original);
+
+ return users;
+}
+
const search = (state = DEFAULT_STATE, action) => {
switch (action.type) {
case 'SEARCH/INPUT_CHANGE':
return {
...state,
searchInput: action.typedValue,
- searchResults: [
- { type: 's', value: '18561' },
- { type: 'c', value: '5H2' },
- { type: 't', value: 'akh' },
- { type: 'r', value: '008-mk' },
- ],
+ searchResults: getSearchResults(action.typedValue),
};
case 'SEARCH/FOCUS_CHANGE':
return {