2022-04-25 15:15:17 +02:00
|
|
|
import {
|
|
|
|
ColorScheme,
|
|
|
|
Container,
|
|
|
|
LoadingOverlay,
|
|
|
|
MantineProvider,
|
2022-05-11 14:18:36 +02:00
|
|
|
Stack,
|
2022-04-25 15:15:17 +02:00
|
|
|
} from "@mantine/core";
|
|
|
|
import { ModalsProvider } from "@mantine/modals";
|
|
|
|
import { NotificationsProvider } from "@mantine/notifications";
|
|
|
|
import { getCookie } from "cookies-next";
|
|
|
|
import { GetServerSidePropsContext } from "next";
|
|
|
|
import type { AppProps } from "next/app";
|
|
|
|
import { useEffect, useState } from "react";
|
2022-05-11 14:18:36 +02:00
|
|
|
import Footer from "../components/Footer";
|
2022-04-25 15:15:17 +02:00
|
|
|
import ThemeProvider from "../components/mantine/ThemeProvider";
|
|
|
|
import Header from "../components/navBar/NavBar";
|
2022-05-16 13:11:51 +02:00
|
|
|
import GlobalStyle from "../styles/global.style";
|
|
|
|
import globalStyle from "../styles/mantine.style";
|
2022-05-02 08:22:53 +02:00
|
|
|
import aw from "../utils/appwrite.util";
|
2022-04-25 15:15:17 +02:00
|
|
|
import authUtil, { IsSignedInContext } from "../utils/auth.util";
|
2022-05-02 08:22:53 +02:00
|
|
|
import configUtil, { ConfigContext } from "../utils/config.util";
|
2022-04-25 15:15:17 +02:00
|
|
|
import { GlobalLoadingContext } from "../utils/loading.util";
|
|
|
|
|
2022-05-02 22:42:27 +02:00
|
|
|
let environmentVariables: any = {};
|
2022-04-25 15:15:17 +02:00
|
|
|
|
2022-05-02 22:42:27 +02:00
|
|
|
function App(
|
|
|
|
props: AppProps & { colorScheme: ColorScheme; environmentVariables: any }
|
|
|
|
) {
|
|
|
|
const { Component, pageProps } = props;
|
2022-04-25 15:15:17 +02:00
|
|
|
const [colorScheme, setColorScheme] = useState<ColorScheme>(
|
|
|
|
props.colorScheme
|
|
|
|
);
|
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
const [isSignedIn, setIsSignedIn] = useState(false);
|
2022-05-02 22:42:27 +02:00
|
|
|
|
|
|
|
if (Object.keys(props.environmentVariables).length != 0) {
|
|
|
|
environmentVariables = props.environmentVariables;
|
|
|
|
}
|
2022-05-02 08:22:53 +02:00
|
|
|
|
|
|
|
const getInitalData = async () => {
|
2022-04-25 15:15:17 +02:00
|
|
|
setIsLoading(true);
|
2022-05-02 08:22:53 +02:00
|
|
|
aw.setEndpoint(environmentVariables.APPWRITE_HOST);
|
2022-04-25 15:15:17 +02:00
|
|
|
setIsSignedIn(await authUtil.isSignedIn());
|
|
|
|
setIsLoading(false);
|
|
|
|
};
|
|
|
|
useEffect(() => {
|
2022-05-02 08:22:53 +02:00
|
|
|
getInitalData();
|
2022-04-25 15:15:17 +02:00
|
|
|
}, []);
|
|
|
|
return (
|
|
|
|
<MantineProvider withGlobalStyles withNormalizeCSS theme={globalStyle}>
|
|
|
|
<ThemeProvider colorScheme={colorScheme} setColorScheme={setColorScheme}>
|
2022-05-16 13:11:51 +02:00
|
|
|
<GlobalStyle />
|
2022-04-25 15:15:17 +02:00
|
|
|
<NotificationsProvider>
|
|
|
|
<ModalsProvider>
|
|
|
|
<GlobalLoadingContext.Provider value={{ isLoading, setIsLoading }}>
|
|
|
|
{isLoading ? (
|
|
|
|
<LoadingOverlay visible overlayOpacity={1} />
|
|
|
|
) : (
|
2022-05-02 08:22:53 +02:00
|
|
|
<ConfigContext.Provider value={environmentVariables}>
|
|
|
|
<IsSignedInContext.Provider value={isSignedIn}>
|
|
|
|
<LoadingOverlay visible={isLoading} overlayOpacity={1} />
|
2022-05-11 14:18:36 +02:00
|
|
|
<Stack justify="space-between" sx={{ minHeight: "100vh" }}>
|
|
|
|
<div>
|
|
|
|
<Header />
|
|
|
|
<Container>
|
|
|
|
<Component {...pageProps} />
|
|
|
|
</Container>
|
|
|
|
</div>
|
|
|
|
<Footer />
|
|
|
|
</Stack>
|
2022-05-02 08:22:53 +02:00
|
|
|
</IsSignedInContext.Provider>
|
|
|
|
</ConfigContext.Provider>
|
2022-04-25 15:15:17 +02:00
|
|
|
)}
|
|
|
|
</GlobalLoadingContext.Provider>
|
|
|
|
</ModalsProvider>
|
|
|
|
</NotificationsProvider>
|
|
|
|
</ThemeProvider>
|
|
|
|
</MantineProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|
|
|
|
|
2022-05-02 22:42:27 +02:00
|
|
|
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => {
|
|
|
|
return {
|
|
|
|
environmentVariables: configUtil.getGonfig(),
|
|
|
|
colorScheme: getCookie("mantine-color-scheme", ctx) || "light",
|
|
|
|
};
|
|
|
|
};
|