import React, { useEffect } from "react"; import { Navigate, Routes, Route, useLocation, useMatch, } from "react-router-dom"; // we include our base SASS here to ensure it is loaded // and applied before any component specific style import "./app.scss"; import { WRITER_MODE, PLACEMENT_ENABLED, PLUS_IS_ENABLED } from "./env"; import { Homepage } from "./homepage"; import { Document } from "./document"; import { A11yNav } from "./ui/molecules/a11y-nav"; import { Footer } from "./ui/organisms/footer"; import { TopNavigation } from "./ui/organisms/top-navigation"; import { SiteSearch } from "./site-search"; import { PageNotFound } from "./page-not-found"; import { Plus } from "./plus"; import { About } from "./about"; import { getCategoryByPathname } from "./utils"; import { Community } from "./community"; import { ContributorSpotlight } from "./contributor-spotlight"; import { useIsServer, usePing } from "./hooks"; import { useGleanPage } from "./telemetry/glean-context"; import { MainContentContainer } from "./ui/atoms/page-content"; import { Loading } from "./ui/atoms/loading"; import { Advertising } from "./advertising"; import { HydrationData } from "../../libs/types/hydration"; import { TopPlacement } from "./ui/organisms/placement"; import { Blog } from "./blog"; import { Newsletter } from "./newsletter"; import { Curriculum } from "./curriculum"; import { useGA } from "./ga-context"; if (!("adoptedStyleSheets" in Document.prototype)) { // Polyfill for CSSStyleSheet() constructor etc, mainly for Safari < 16.4. // Required for webpack css-loader exportType "css-style-sheet". // Note: Async import is a compromise, as top-level await requires Safari 15+. import( /* webpackChunkName: "construct-style-sheets-polyfill" */ "construct-style-sheets-polyfill" ); } const AllFlaws = React.lazy(() => import("./flaws")); const Translations = React.lazy(() => import("./translations")); const WritersHomepage = React.lazy(() => import("./writers-homepage")); const Sitemap = React.lazy(() => import("./sitemap")); const Playground = React.lazy(() => import("./playground")); const Observatory = React.lazy(() => import("./observatory")); function Layout({ pageType, children }) { const { pathname } = useLocation(); const [category, setCategory] = React.useState( getCategoryByPathname(pathname) ); React.useEffect(() => { setCategory(getCategoryByPathname(pathname)); }, [pathname]); return ( <>
{!["document-page", "curriculum", "observatory"].includes(pageType) && (
)} {children}