92 lines
2.6 KiB
TypeScript
Executable File
92 lines
2.6 KiB
TypeScript
Executable File
// @ts-ignore
|
|
import "../styles/main.css";
|
|
|
|
import React from "react";
|
|
import type {
|
|
BunextPageHeadFCProps,
|
|
BunextRootComponentProps,
|
|
} from "@moduletrace/bunext/types";
|
|
|
|
import type { AppContextObject, AppStateObject } from "@/src/types";
|
|
import Layout from "../layouts/main";
|
|
import AdminLayout from "../layouts/admin";
|
|
import LoginShell from "../components/general/login-shell";
|
|
|
|
export const AppContext = React.createContext<AppContextObject>(
|
|
{} as AppContextObject,
|
|
);
|
|
|
|
/**
|
|
* # NextApp App Root
|
|
* @description Root component for NextApp App (Next.js)
|
|
*/
|
|
export default function SBFApp({
|
|
children,
|
|
props,
|
|
url,
|
|
query,
|
|
}: BunextRootComponentProps) {
|
|
const [refresh, setRefresh] = React.useState(0);
|
|
const [appState, setAppState] = React.useState<AppStateObject>({
|
|
likes: null,
|
|
});
|
|
|
|
const appContextObject: AppContextObject = {
|
|
user: null,
|
|
appState,
|
|
setAppState,
|
|
refresh,
|
|
setRefresh,
|
|
pageProps: { ...props, url },
|
|
query,
|
|
};
|
|
|
|
if (url?.pathname.startsWith("/admin")) {
|
|
return (
|
|
<AppContext.Provider value={appContextObject}>
|
|
<AdminLayout>{children}</AdminLayout>
|
|
</AppContext.Provider>
|
|
);
|
|
}
|
|
|
|
if (url?.pathname.startsWith("/auth")) {
|
|
return (
|
|
<AppContext.Provider value={appContextObject}>
|
|
<LoginShell>{children}</LoginShell>
|
|
</AppContext.Provider>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<AppContext.Provider value={appContextObject}>
|
|
<Layout
|
|
// no_header_divider={
|
|
// url?.pathname ? ["/"].includes(url.pathname) : undefined
|
|
// }
|
|
blank={
|
|
url?.pathname
|
|
? ["/auth/logout"].includes(url.pathname)
|
|
: undefined
|
|
}
|
|
>
|
|
{children}
|
|
</Layout>
|
|
</AppContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function Head({ serverRes, ctx }: BunextPageHeadFCProps) {
|
|
return (
|
|
<>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link
|
|
rel="preconnect"
|
|
href="https://fonts.gstatic.com"
|
|
crossOrigin=""
|
|
/>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ace.min.js" />
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ext-language_tools.min.js" />
|
|
</>
|
|
);
|
|
}
|