// @ts-ignore import "../styles/main.css"; import React from "react"; import type { BunextPageHeadFCProps, BunextRootComponentProps, } from "@moduletrace/bunext/types"; import type { AppContextObject, AppStateObject, PagePropsType, } from "@/src/types"; import { SiteData } from "@/src/data/site-data"; import installDisplayName from "@/src/utils/install-display-name"; import installIconBase from "@/src/utils/install-icon-base"; import Layout from "../layouts/main"; import AuthLayout from "../layouts/auth"; import BotsLayout from "../layouts/bots"; import ThemeInitScript from "../components/general/theme-init-script"; import PwaInitScript from "../components/general/pwa-init-script"; import ServiceWorkerRegistrar from "../components/general/service-worker-registrar"; export const AppContext = React.createContext( {} as AppContextObject, ); /** * # NextApp App Root * @description Root component for NextApp App (Next.js) */ export default function App({ children, props, url, query, }: BunextRootComponentProps) { const [refresh, setRefresh] = React.useState(0); const [appState, setAppState] = React.useState({ likes: null, }); const page_props = props as PagePropsType; const appContextObject: AppContextObject = { user: page_props?.user || null, user_types: page_props?.user_types || null, appState, setAppState, refresh, setRefresh, SITE_DATA: { siteName: SiteData["SiteName"], }, pageProps: { ...props, url }, query, }; if (url?.pathname.startsWith("/admin")) { return ( {children} ); } if ( url?.pathname.startsWith("/auth") && !url.pathname.startsWith("/auth/logout") ) { return ( {children} ); } return ( {children} ); } export function Head({ serverRes, ctx }: BunextPageHeadFCProps) { /** * iOS names a home-screen app from these tags, not the manifest. */ const root_props = serverRes?.props as PagePropsType | undefined; const app_name = installDisplayName({ install_name: root_props?.install_name }); /** * The install's own icon set, when it has one (Settings > General). */ const icon_base = installIconBase({ icon: root_props?.install_icon }); return ( <> {icon_base ? null : ( )} ); }