import React from "react"; import { useSearchParams } from "react-router-dom"; import { useIsServer } from "../hooks"; import { Loading } from "../ui/atoms/loading"; import { MainContentContainer } from "../ui/atoms/page-content"; import { useGleanClick } from "../telemetry/glean-context"; import "./index.scss"; import { SidePlacement } from "../ui/organisms/placement"; import { CLIENT_SIDE_NAVIGATION } from "../telemetry/constants"; const SiteSearchForm = React.lazy(() => import("./form")); const SearchResults = React.lazy(() => import("./search-results")); export function SiteSearch() { const isServer = useIsServer(); const gleanClick = useGleanClick(); const [searchParams] = useSearchParams(); const query = searchParams.get("q"); const page = searchParams.get("page"); React.useEffect(() => { if (query) { let title = `Search: "${query}"`; if (page && page !== "1") { title += ` (page ${page})`; } document.title = title; } else { document.title = "No query, no results."; } }, [query, page]); const mountCounter = React.useRef(0); React.useEffect(() => { if (mountCounter.current > 0) { const location = window.location.toString(); gleanClick(`${CLIENT_SIDE_NAVIGATION}: ${location}`); } // By counting every time a document is mounted, we can use this to know if // a client-side navigation happened. mountCounter.current++; }, [query, page, gleanClick]); return (
{query ? (

Search results for: {query}{" "} {page && page !== "1" && `(page ${page})`}

) : ( !isServer &&

No query, no results.

)} {!isServer && ( }> )} {!isServer && query && ( }> )}
); }