From bce2e080ae70d9a7f7054f432d25206fbd813a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez=20Mu=C3=B1oz?= Date: Tue, 10 Dec 2024 18:10:14 +0100 Subject: [PATCH] reflects search value from URL in table search --- client/src/components/ui/search.tsx | 4 +++- client/src/containers/overview/table/toolbar/search/index.tsx | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/components/ui/search.tsx b/client/src/components/ui/search.tsx index 188d6d53..2f5b1dcf 100644 --- a/client/src/components/ui/search.tsx +++ b/client/src/components/ui/search.tsx @@ -17,6 +17,7 @@ export default function Search({ className, autoFocus = false, showCloseIconAlways = false, + defaultValue = "", }: { placeholder?: string; onChange: (v: string | undefined) => void; @@ -24,8 +25,9 @@ export default function Search({ className?: HTMLDivElement["className"] | undefined; autoFocus?: HTMLInputElement["autofocus"] | undefined; showCloseIconAlways?: boolean | undefined; + defaultValue?: string | undefined; }) { - const [value, setValue] = useState(""); + const [value, setValue] = useState(defaultValue); const debouncedOnChange = useDebounce((value: string | undefined) => { onChange(value); diff --git a/client/src/containers/overview/table/toolbar/search/index.tsx b/client/src/containers/overview/table/toolbar/search/index.tsx index 84734999..b0971626 100644 --- a/client/src/containers/overview/table/toolbar/search/index.tsx +++ b/client/src/containers/overview/table/toolbar/search/index.tsx @@ -5,7 +5,7 @@ import { useGlobalFilters } from "@/app/(overview)/url-store"; import Search from "@/components/ui/search"; export default function SearchProjectsTable() { - const [, setFilters] = useGlobalFilters(); + const [{ keyword }, setFilters] = useGlobalFilters(); const handleSearch = async ( v: Parameters["onChange"]>[0], @@ -18,6 +18,7 @@ export default function SearchProjectsTable() { placeholder="Search project" onChange={handleSearch} className="flex-1" + defaultValue={keyword} /> ); }