aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/lib
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-19 22:49:26 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-19 22:49:26 +0100
commit5be066cc2714ca6cbd75d8786c859d8767df0ccb (patch)
tree4b9b66e68612eb9df03a73453907031c03420415 /src/client/react/lib
parent50671ed027f874992ac50cfb21e123f579440737 (diff)
Merge reducers into single file
Diffstat (limited to 'src/client/react/lib')
-rw-r--r--src/client/react/lib/getSearchResults.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/client/react/lib/getSearchResults.js b/src/client/react/lib/getSearchResults.js
new file mode 100644
index 0000000..fa012ac
--- /dev/null
+++ b/src/client/react/lib/getSearchResults.js
@@ -0,0 +1,22 @@
+import FuzzySearch from 'fuzzy-search';
+import uniqBy from 'lodash/uniqBy';
+import users from '../users';
+
+function getSearchResults(query) {
+ const searcher = new FuzzySearch(users.allUsers, ['value', 'alt']);
+
+ if (query.trim() === '') {
+ return [];
+ }
+
+ const allResults = searcher.search(query);
+ const uniqResults = uniqBy(allResults, result => result.id);
+ const firstResults = uniqResults.splice(0, 4);
+
+ const userIds = firstResults.map(result => result.id);
+
+ return userIds;
+}
+
+export default getSearchResults;
+