Skip to content

Commit

Permalink
refactor: make it easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
YassinEldeeb committed Dec 9, 2022
1 parent c2b2bae commit 767dd1e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/components/src/components/marketplace-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ export const MarketplaceSearch = ({
const items = useMemo(() => {
let results = null;
if (query && queryList) {
return (results = queryList.items.filter(
e =>
fuzzy
.filter(
// Removes all special characters from the query string for better fuzzy matching
query.replace(/[^\w\s]/gi, ''),
// Mapping the queryList items into a list of strings including the titles
queryList.items.map(e => e.title),
)
.map(e => e.original)
// Filtering only the items that have been selected by the fuzzy matcher
.includes(e.title),
{},
));
const matchedResults = fuzzy
.filter(
// Removes all special characters from the query string for better fuzzy matching
query.replace(/[^\w\s]/gi, ''),
// Mapping the queryList items into a list of strings including the titles
queryList.items.map(e => e.title),
)
.map(e => e.original);

const filteredItems = queryList.items.filter(e => matchedResults.includes(e.title));
results = filteredItems;
}
return results;
}, [query, queryList]);
Expand Down

0 comments on commit 767dd1e

Please sign in to comment.