From 8f8f60187123fc48c573e972cb216a2daf885479 Mon Sep 17 00:00:00 2001 From: pragnyanramtha Date: Tue, 19 May 2026 20:01:55 +0000 Subject: [PATCH] fix: reset search loading state after navigation --- frontend/app/components/SearchForm.tsx | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/frontend/app/components/SearchForm.tsx b/frontend/app/components/SearchForm.tsx index 030cb3e..e954e52 100644 --- a/frontend/app/components/SearchForm.tsx +++ b/frontend/app/components/SearchForm.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { Search, Loader2 } from "lucide-react"; import { motion } from "framer-motion"; @@ -8,15 +8,19 @@ import { cn } from "@/lib/utils"; export function SearchForm() { const [query, setQuery] = useState(""); - const [isLoading, setIsLoading] = useState(false); + const [isPending, startTransition] = useTransition(); const router = useRouter(); + const trimmedQuery = query.trim(); + const canSearch = trimmedQuery.length > 0; + const isSearchEnabled = canSearch && !isPending; const handleSearch = (e: React.FormEvent) => { e.preventDefault(); - if (!query.trim()) return; - setIsLoading(true); - // Simple routing to search page with query - router.push(`/search?q=${encodeURIComponent(query.trim())}`); + if (!canSearch) return; + + startTransition(() => { + router.push(`/search?q=${encodeURIComponent(trimmedQuery)}`); + }); }; return ( @@ -44,15 +48,23 @@ export function SearchForm() {