Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
timc1 committed Aug 16, 2023
1 parent 3f2b2a7 commit 36043bb
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/useMatches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ export function useMatches() {
}, [getDeepResults, rootResults, emptySearch]);

const fuseOptions = {
keys: [{
name: "name",
weight: 0.5
},
{
name: "keywords",
getFn: (item) => item.keywords.split(","), // make keyword an array. so fuse can look through words individually
weight: 0.5
},
"subtitle"],
keys: [
{
name: "name",
weight: 0.5,
},
{
name: "keywords",
getFn: (item) => item.keywords.split(","), // make keyword an array. so fuse can look through words individually
weight: 0.5,
},
"subtitle",
],
includeScore: true,
includeMatches: true,
threshold: 0.2,
Expand Down Expand Up @@ -190,7 +192,11 @@ type Match = {
score: number;
};

function useInternalMatches(filtered: ActionImpl[], search: string, fuse: Fuse<ActionImpl>) {
function useInternalMatches(
filtered: ActionImpl[],
search: string,
fuse: Fuse<ActionImpl>
) {
const value = React.useMemo(
() => ({
filtered,
Expand All @@ -212,12 +218,12 @@ function useInternalMatches(filtered: ActionImpl[], search: string, fuse: Fuse<A
const searchResults = fuse.search(throttledSearch);
// Format the search results to match the existing structure
matches = searchResults.map(({ item: action, score }) => ({
score: 1 / (score + 1), // Convert the Fuse score to the format used in the original code
score: 1 / ((score ?? 0) + 1), // Convert the Fuse score to the format used in the original code
action,
}));

return matches;
}, [throttledFiltered, throttledSearch]) as Match[];
}, [throttledFiltered, throttledSearch, fuse]) as Match[];
}

/**
Expand Down

0 comments on commit 36043bb

Please sign in to comment.