From b1f0f13dc4450794c2fdd0a2f9ad676fcebf7dc6 Mon Sep 17 00:00:00 2001 From: Adebayo John <105176570+JohnOluB@users.noreply.github.com> Date: Tue, 28 Apr 2026 00:45:12 +0000 Subject: [PATCH 1/2] feat(search): persist filters and sort state in URL params (#272) --- .../search/AdvancedSearchInterface.tsx | 64 +++-- src/hooks/useSearchState.ts | 218 ++++++++++++++++++ 2 files changed, 268 insertions(+), 14 deletions(-) create mode 100644 src/hooks/useSearchState.ts diff --git a/src/components/search/AdvancedSearchInterface.tsx b/src/components/search/AdvancedSearchInterface.tsx index ad057d3c..769726a6 100644 --- a/src/components/search/AdvancedSearchInterface.tsx +++ b/src/components/search/AdvancedSearchInterface.tsx @@ -2,17 +2,15 @@ import React, { useState, useCallback } from 'react'; import { - Search, Filter, - Settings, - Sparkles, - ArrowLeft, - X, History, TrendingUp, BrainCircuit, + Sparkles, + Share2, + Check, } from 'lucide-react'; -import { useAdvancedSearch } from '../../hooks/useAdvancedSearch'; +import { useSearchState } from '../../hooks/useSearchState'; import { IntelligentAutoComplete } from './IntelligentAutoComplete'; import { FacetedFilterSystem } from './FacetedFilterSystem'; import { SearchResultsVisualizer } from './SearchResultsVisualizer'; @@ -28,10 +26,16 @@ export const AdvancedSearchInterface = React.memo(() => { results, isSearching, history, - } = useAdvancedSearch(); + copyShareableUrl, + } = useSearchState(); const [showFilters, setShowFilters] = useState(false); - const [hasSearched, setHasSearched] = useState(false); + const [hasSearched, setHasSearched] = useState(() => { + // Derive initial value — if URL already had a query, we are in "searched" mode + if (typeof window === 'undefined') return false; + return new URLSearchParams(window.location.search).has('q'); + }); + const [copied, setCopied] = useState(false); const handleSearch = useCallback( (text: string) => { @@ -48,6 +52,14 @@ export const AdvancedSearchInterface = React.memo(() => { setHasSearched(false); }, [clearFilters, updateSearchText]); + const handleShare = useCallback(async () => { + const ok = await copyShareableUrl(); + if (ok) { + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } + }, [copyShareableUrl]); + return (
{/* Search Header Section */} @@ -79,6 +91,8 @@ export const AdvancedSearchInterface = React.memo(() => { history={history} />
+ + {/* Filter toggle */} + + {/* Share button — only shown when there is active search state to share */} + {hasSearched && ( + + )} {/* Quick Insights / Trending Tags */} @@ -123,7 +156,10 @@ export const AdvancedSearchInterface = React.memo(() => { { + clearFilters(); + setHasSearched(false); + }} /> )} @@ -177,7 +213,7 @@ export const AdvancedSearchInterface = React.memo(() => { - {/* Search Insights Tooltip (Utility) */} + {/* History tooltip — bottom-left floating button */}