Removed sorting in exchange for filtering

This commit is contained in:
Tiago Ribeiro
2024-09-11 16:33:05 +01:00
parent 7bfd000213
commit 3ce97b4dcd
4 changed files with 43 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
import {useState, useMemo} from "react";
import Input from "@/components/Low/Input";
import { search } from "@/utils/search";
import {search} from "@/utils/search";
export function useListSearch<T>(fields: string[][], rows: T[]) {
const [text, setText] = useState("");
@@ -8,7 +8,8 @@ export function useListSearch<T>(fields: string[][], rows: T[]) {
const renderSearch = () => <Input label="Search" type="text" name="search" onChange={setText} placeholder="Enter search text" value={text} />;
const updatedRows = useMemo(() => {
return search(text, fields, rows);
if (text.length > 0) return search(text, fields, rows);
return rows;
}, [fields, rows, text]);
return {