aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-16 22:10:33 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-16 22:10:33 +0100
commit065c798078586b98f974c4f8ee2d1a7af1ad9218 (patch)
tree8f7c3e6132da54438b26a169e9d1ecab95d3c6df /src/client/react/reducers
parent48ca524d275e05d39904a40486fb2a146eb37371 (diff)
Add client support for alts
Diffstat (limited to 'src/client/react/reducers')
-rw-r--r--src/client/react/reducers/search.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js
index 6293b8a..2f02874 100644
--- a/src/client/react/reducers/search.js
+++ b/src/client/react/reducers/search.js
@@ -1,4 +1,5 @@
-import fuzzy from 'fuzzy';
+import FuzzySearch from 'fuzzy-search';
+import uniqBy from 'lodash/uniqBy';
import users from '../users';
const DEFAULT_STATE = {
@@ -11,16 +12,17 @@ const DEFAULT_STATE = {
};
function getSearchResults(allUsers, query) {
+ const searcher = new FuzzySearch(allUsers, ['value', 'alt']);
+
if (query.trim() === '') {
return [];
}
- const allResults = fuzzy.filter(query, allUsers, {
- extract: user => user.value,
- });
+ const allResults = searcher.search(query);
+ const uniqResults = uniqBy(allResults, result => result.id);
+ const firstResults = uniqResults.splice(0, 4);
- const firstResults = allResults.splice(0, 4);
- const userIds = firstResults.map(result => result.original.id);
+ const userIds = firstResults.map(result => result.id);
return userIds;
}