diff --git a/app/page.tsx b/app/page.tsx index 578835b..0de7fb4 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -60,9 +60,9 @@ function HomePage() { setAvailableSources(cached.availableSources); setHasSearched(true); } else { - // Trigger automatic search for URL query + // Trigger automatic search for URL query (won't clear cache, will use existing if valid) console.log('🔍 Auto-searching for URL query:', urlQuery); - setTimeout(() => performSearch(urlQuery), 100); + setTimeout(() => performSearch(urlQuery, false), 100); } } else if (cached) { // No URL query but cache exists - restore last search @@ -113,9 +113,18 @@ function HomePage() { } }; - const performSearch = async (searchQuery: string) => { + const performSearch = async (searchQuery: string, shouldClearCache: boolean = true) => { if (!searchQuery.trim() || loading) return; + // Only clear cache if user manually clicked search button + if (shouldClearCache) { + const cached = loadFromCache(); + if (cached && cached.query === searchQuery) { + console.log('🗑️ Clearing old cache for manual search'); + localStorage.removeItem(CACHE_KEY); + } + } + // Abort any previous search if (abortControllerRef.current) { abortControllerRef.current.abort(); @@ -278,7 +287,8 @@ function HomePage() { const handleSearch = async (e: React.FormEvent) => { e.preventDefault(); - await performSearch(query); + // Pass true to clear cache when user manually clicks search + await performSearch(query, true); }; const getSourceName = (sourceId: string): string => { @@ -309,7 +319,17 @@ function HomePage() {