From 5be066cc2714ca6cbd75d8786c859d8767df0ccb Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Mon, 19 Feb 2018 22:49:26 +0100 Subject: Merge reducers into single file --- src/client/react/lib/getSearchResults.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/client/react/lib/getSearchResults.js (limited to 'src/client/react/lib') 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; + -- cgit v1.1