import { useSearchParams } from 'react-router'; import { Loader2, Search } from 'lucide-react'; import { Input } from '@/components/ui/input'; import { MediaGrid } from './MediaCard'; import { QUERY_PARAM } from './shared'; import { useJellyfinSearch } from './useJellyfinData'; // Search across every video library. // // The term is `?q=` — in the URL, not in component state, so a result set is a link and the browser's own // back button steps through what you looked for. `replace` on every keystroke keeps that history one entry // per search rather than one per letter. export const SearchSection = () => { const [params, setParams] = useSearchParams(); const term = params.get(QUERY_PARAM) ?? ''; const { data, isFetching } = useJellyfinSearch(term); const setTerm = (value: string) => { const next = new URLSearchParams(params); if (value) next.set(QUERY_PARAM, value); else next.delete(QUERY_PARAM); setParams(next, { replace: true }); }; const items = data?.Items ?? []; return (
Type at least two characters.
) : items.length ? (Nothing matched “{term}”.
)}