import { GetWebsiteInterfaceQuery, StrapiImage, } from "graphql/operations-types"; import MainPanel from "./Panels/MainPanel"; import Head from "next/head"; import { useSwipeable } from "react-swipeable"; import { useRouter } from "next/router"; import Button from "components/Button"; import { getOgImage, OgImage, prettyLanguage } from "queries/helpers"; import { useMediaCoarse, useMediaMobile } from "hooks/useMediaQuery"; import ReactTooltip from "react-tooltip"; import { useAppLayout } from "contexts/AppLayoutContext"; import { ImageQuality } from "./Img"; import Popup from "./Popup"; import { useEffect, useState } from "react"; import Select from "./Select"; import { AppStaticProps } from "queries/getAppStaticProps"; interface AppLayoutProps extends AppStaticProps { subPanel?: React.ReactNode; subPanelIcon?: string; contentPanel?: React.ReactNode; title?: string; navTitle: string; thumbnail?: StrapiImage; description?: string; extra?: React.ReactNode; } export default function AppLayout(props: AppLayoutProps): JSX.Element { const { langui, currencies, languages, subPanel, contentPanel } = props; const router = useRouter(); const isMobile = useMediaMobile(); const isCoarse = useMediaCoarse(); const appLayout = useAppLayout(); const sensibilitySwipe = 1.1; const handlers = useSwipeable({ onSwipedLeft: (SwipeEventData) => { if (SwipeEventData.velocity < sensibilitySwipe) return; if (appLayout.mainPanelOpen) { appLayout.setMainPanelOpen(false); } else if (subPanel && contentPanel) { appLayout.setSubPanelOpen(true); } }, onSwipedRight: (SwipeEventData) => { if (SwipeEventData.velocity < sensibilitySwipe) return; if (appLayout.subPanelOpen) { appLayout.setSubPanelOpen(false); } else { appLayout.setMainPanelOpen(true); } }, }); const mainPanelClass = `fixed desktop:left-0 desktop:top-0 desktop:bottom-0 ${ appLayout.mainPanelReduced ? "desktop:w-[6rem]" : "desktop:w-[20rem]" }`; const subPanelClass = `fixed desktop:top-0 desktop:bottom-0 desktop:w-[20rem] ${ appLayout.mainPanelReduced ? " desktop:left-[6rem]" : "desktop:left-[20rem]" }`; let contentPanelClass = ""; if (subPanel) { contentPanelClass = `fixed desktop:top-0 desktop:bottom-0 desktop:right-0 ${ appLayout.mainPanelReduced ? "desktop:left-[26rem]" : "desktop:left-[40rem]" }`; } else if (contentPanel) { contentPanelClass = `fixed desktop:top-0 desktop:bottom-0 desktop:right-0 ${ appLayout.mainPanelReduced ? "desktop:left-[6rem]" : "desktop:left-[20rem]" }`; } const turnSubIntoContent = subPanel && !contentPanel; const titlePrefix = "Accord’s Library"; const metaImage: OgImage = props.thumbnail ? getOgImage(ImageQuality.Og, props.thumbnail) : { image: "/default_og.jpg", width: 1200, height: 630, alt: "Accord's Library Logo", }; const ogTitle = props.title ? props.title : props.navTitle; const metaDescription = props.description ? props.description : langui.default_description; useEffect(() => { document.getElementsByTagName("html")[0].style.fontSize = `${ (appLayout.fontSize || 1) * 100 }%`; }, [appLayout.fontSize]); const currencyOptions = currencies.map((currency) => { return currency.attributes.code; }); const [currencySelect, setCurrencySelect] = useState(-1); useEffect(() => { appLayout.currency && setCurrencySelect(currencyOptions.indexOf(appLayout.currency)); // eslint-disable-next-line react-hooks/exhaustive-deps }, [appLayout.currency]); useEffect(() => { currencySelect >= 0 && appLayout.setCurrency(currencyOptions[currencySelect]); // eslint-disable-next-line react-hooks/exhaustive-deps }, [currencySelect]); return (
{`${titlePrefix} - ${ogTitle}`} {/* Content panel */}
{contentPanel ? ( contentPanel ) : (

{langui.select_option_sidebar}

)}
{/* Background when navbar is opened */}
{ appLayout.setMainPanelOpen(false); appLayout.setSubPanelOpen(false); }} >
{/* Sub panel */} {subPanel && (
{subPanel}
)} {/* Main panel */}
{/* Main panel minimize button*/}
appLayout.setMainPanelReduced(!appLayout.mainPanelReduced) } >
{/* Navbar */}
{ appLayout.setMainPanelOpen(!appLayout.mainPanelOpen); appLayout.setSubPanelOpen(false); }} > {appLayout.mainPanelOpen ? "close" : "menu"}

{props.navTitle}

{ appLayout.setSubPanelOpen(!appLayout.subPanelOpen); appLayout.setMainPanelOpen(false); }} > {subPanel && !turnSubIntoContent ? appLayout.subPanelOpen ? "close" : props.subPanelIcon ? props.subPanelIcon : "tune" : ""}

{langui.select_language}

{languages.map((language) => ( ))}

{langui.settings}

{langui.theme}

{langui.currency}

appLayout.setPlayerName((e.target as HTMLInputElement).value) } />
{props.extra}
); }