import { useNavigate } from "@tanstack/react-router"; import { Search } from "lucide-react"; import { type ChangeEvent, type FormEvent, useCallback, useState } from "react"; import { type BrowseQuery, browseHref, DEFAULT_WINDOW } from "./links"; /** * Search box for the plugin pages. Typing replaces the URL with the browse page for the term, * keeping `scope`'s category and sort. Without JavaScript the form submits the same URL. */ export function PluginSearch({ scope, className }: { scope: BrowseQuery; className?: string }) { const navigate = useNavigate(); const [term, setTerm] = useState(scope.q ?? ""); const handleChange = useCallback( (event: ChangeEvent) => { const next = event.target.value; setTerm(next); void navigate({ href: browseHref({ ...scope, q: next.trim() ? next : undefined }), replace: true, }); }, [navigate, scope], ); const handleSubmit = useCallback((event: FormEvent) => event.preventDefault(), []); return (
{scope.sort === "new" && } {scope.sort === "installs" && scope.window !== DEFAULT_WINDOW && ( )}
); }