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 (
setTerm(ev.target.value)} placeholder="Search films, shows and episodes" className="h-8 border-0 bg-transparent px-0 shadow-none focus-visible:ring-0" autoFocus spellCheck={false} /> {isFetching && }
{term.trim().length < 2 ? (

Type at least two characters.

) : items.length ? ( ) : ( !isFetching &&

Nothing matched “{term}”.

)}
); };