useBasicSearch: stricter search criteria

This commit is contained in:
Sidney Alcantara
2022-09-23 12:05:36 +10:00
parent 67c2a3b663
commit 0acca9d859
2 changed files with 5 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import { useState } from "react";
import { useDebouncedCallback } from "use-debounce";
import { matchSorter } from "match-sorter";
import { matchSorter, rankings } from "match-sorter";
export function useBasicSearch<T>(
list: T[],
@@ -10,7 +10,9 @@ export function useBasicSearch<T>(
const [query, setQuery] = useState("");
const handleQuery = useDebouncedCallback(setQuery, debounce);
const results = query ? matchSorter(list, query, { keys }) : list;
const results = query
? matchSorter(list, query, { keys, threshold: rankings.ACRONYM })
: list;
return [results, query, handleQuery] as const;
}

View File

@@ -44,7 +44,7 @@ import { useScrollToHash } from "@src/hooks/useScrollToHash";
const SEARCH_KEYS = ["id", "name", "section", "description"];
export default function HomePage() {
export default function TablesPage() {
const [userRoles] = useAtom(userRolesAtom, projectScope);
const [userSettings] = useAtom(userSettingsAtom, projectScope);
const [updateUserSettings] = useAtom(updateUserSettingsAtom, projectScope);