import Head from "next/head"; import { useRouter } from "next/router"; import { useEffect, useMemo, useState } from "react"; import { useSwipeable } from "react-swipeable"; import UAParser from "ua-parser-js"; import { useBoolean, useIsClient } from "usehooks-ts"; import Script from "next/script"; import { layout } from "../../design.config"; import { Ico, Icon } from "./Ico"; import { ButtonGroup } from "./Inputs/ButtonGroup"; import { OrderableList } from "./Inputs/OrderableList"; import { Select } from "./Inputs/Select"; import { TextInput } from "./Inputs/TextInput"; import { MainPanel } from "./Panels/MainPanel"; import { Popup } from "./Popup"; import { AnchorIds } from "hooks/useScrollTopOnChange"; import { filterHasAttributes, isDefined, isUndefined } from "helpers/others"; import { prettyLanguage } from "helpers/formatters"; import { cIf, cJoin } from "helpers/className"; import { useAppLayout } from "contexts/AppLayoutContext"; import { Button } from "components/Inputs/Button"; import { OpenGraph, TITLE_PREFIX, TITLE_SEPARATOR } from "helpers/openGraph"; import { useIs1ColumnLayout, useIsScreenAtLeast, } from "hooks/useContainerQuery"; import { useOnResize } from "hooks/useOnResize"; /* * ╭─────────────╮ * ────────────────────────────────────────╯ CONSTANTS ╰────────────────────────────────────────── */ const SENSIBILITY_SWIPE = 1.1; /* * ╭─────────────╮ * ───────────────────────────────────────╯ COMPONENT ╰─────────────────────────────────────────── */ export interface AppLayoutRequired { openGraph: OpenGraph; } interface Props extends AppLayoutRequired { subPanel?: React.ReactNode; subPanelIcon?: Icon; contentPanel?: React.ReactNode; contentPanelScroolbar?: boolean; } // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ export const AppLayout = ({ subPanel, contentPanel, openGraph, subPanelIcon = Icon.Tune, contentPanelScroolbar = true, }: Props): JSX.Element => { const { configPanelOpen, currency, darkMode, dyslexic, fontSize, mainPanelOpen, mainPanelReduced, menuGestures, playerName, preferredLanguages, selectedThemeMode, subPanelOpen, setConfigPanelOpen, setCurrency, setDarkMode, setDyslexic, setFontSize, setMainPanelOpen, setPlayerName, setPreferredLanguages, setSelectedThemeMode, setSubPanelOpen, toggleMainPanelOpen, toggleSubPanelOpen, setScreenWidth, setContentPanelWidth, setSubPanelWidth, langui, currencies, languages, } = useAppLayout(); const router = useRouter(); const is1ColumnLayout = useIs1ColumnLayout(); const isScreenAtLeastXs = useIsScreenAtLeast("xs"); useOnResize(AnchorIds.Body, (width) => setScreenWidth(width)); useOnResize(AnchorIds.ContentPanel, (width) => setContentPanelWidth(width)); useOnResize(AnchorIds.SubPanel, (width) => setSubPanelWidth(width)); const handlers = useSwipeable({ onSwipedLeft: (SwipeEventData) => { if (menuGestures) { if (SwipeEventData.velocity < SENSIBILITY_SWIPE) return; if (mainPanelOpen) { setMainPanelOpen(false); } else if (isDefined(subPanel) && isDefined(contentPanel)) { setSubPanelOpen(true); } } }, onSwipedRight: (SwipeEventData) => { if (menuGestures) { if (SwipeEventData.velocity < SENSIBILITY_SWIPE) return; if (subPanelOpen) { setSubPanelOpen(false); } else { setMainPanelOpen(true); } } }, }); const turnSubIntoContent = useMemo( () => isDefined(subPanel) && isUndefined(contentPanel), [contentPanel, subPanel] ); const currencyOptions = useMemo( () => filterHasAttributes(currencies, ["attributes"] as const).map( (currentCurrency) => currentCurrency.attributes.code ), [currencies] ); const [currencySelect, setCurrencySelect] = useState(-1); useEffect(() => { if (isDefined(currency)) setCurrencySelect(currencyOptions.indexOf(currency)); }, [currency, currencyOptions]); useEffect(() => { if (currencySelect >= 0) setCurrency(currencyOptions[currencySelect]); }, [currencyOptions, currencySelect, setCurrency]); const isClient = useIsClient(); const { value: hasDisgardSafariWarning, setTrue: disgardSafariWarning } = useBoolean(false); const isSafari = useMemo(() => { if (isClient) { const parser = new UAParser(); return ( parser.getBrowser().name === "Safari" || parser.getOS().name === "iOS" ); } return false; }, [isClient]); return (
{openGraph.title}