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 (
@@ -36,54 +29,16 @@ function GlobalItemsCatalog() {
- {/* Title + search row */} -
+ {/* Title row */} +

Global Gear Catalog

-
- - - - setSearchInput(e.target.value)} - placeholder="Search gear by brand or model..." - className="w-full pl-10 pr-4 py-2.5 bg-white border border-gray-200 rounded-lg text-sm text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-200 focus:border-gray-300 transition-colors" - /> - {searchInput && ( - - )} -
+ {q && ( +

+ Showing results for "{q}" +

+ )}
{/* Results */} @@ -128,7 +83,7 @@ function GlobalItemsCatalog() { />

- {debouncedQuery + {q ? "No items found matching your search" : "No items in the global catalog yet"}