diff --git a/src/client/routes/global-items/index.tsx b/src/client/routes/global-items/index.tsx index 8934772..5f1f4ef 100644 --- a/src/client/routes/global-items/index.tsx +++ b/src/client/routes/global-items/index.tsx @@ -1,27 +1,20 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { ArrowLeft } from "lucide-react"; -import { useEffect, useState } from "react"; +import { z } from "zod"; import { GlobalItemCard } from "../../components/GlobalItemCard"; import { useGlobalItems } from "../../hooks/useGlobalItems"; export const Route = createFileRoute("/global-items/")({ component: GlobalItemsCatalog, + validateSearch: z.object({ + q: z.string().optional().catch(undefined), + }), }); function GlobalItemsCatalog() { - const [searchInput, setSearchInput] = useState(""); - const [debouncedQuery, setDebouncedQuery] = useState(""); + const { q } = Route.useSearch(); - useEffect(() => { - const timer = setTimeout(() => { - setDebouncedQuery(searchInput); - }, 300); - return () => clearTimeout(timer); - }, [searchInput]); - - const { data: items, isLoading } = useGlobalItems( - debouncedQuery || undefined, - ); + const { data: items, isLoading } = useGlobalItems(q || undefined); return (
+ Showing results for "{q}" +
+ )}- {debouncedQuery + {q ? "No items found matching your search" : "No items in the global catalog yet"}