1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-19 13:50:10 +01:00
pingvin-share/src/pages/_app.tsx

76 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-04-25 15:15:17 +02:00
import {
ColorScheme,
Container,
LoadingOverlay,
MantineProvider,
} 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";
import "../../styles/globals.css";
import ThemeProvider from "../components/mantine/ThemeProvider";
import Header from "../components/navBar/NavBar";
import globalStyle from "../styles/global.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";
function App(props: AppProps & { colorScheme: ColorScheme }) {
const { Component, pageProps } = props;
const [colorScheme, setColorScheme] = useState<ColorScheme>(
props.colorScheme
);
const [isLoading, setIsLoading] = useState(true);
const [isSignedIn, setIsSignedIn] = useState(false);
2022-05-02 11:19:24 +02:00
const [environmentVariables, setEnvironmentVariables] = useState<any>({});
2022-05-02 08:22:53 +02:00
const getInitalData = async () => {
2022-04-25 15:15:17 +02:00
setIsLoading(true);
2022-05-02 11:19:24 +02:00
const environmentVariables = await configUtil.getGonfig();
2022-05-02 08:22:53 +02:00
aw.setEndpoint(environmentVariables.APPWRITE_HOST);
2022-05-02 11:19:24 +02:00
setEnvironmentVariables(environmentVariables);
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}>
<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} />
<Header />
<Container>
<Component {...pageProps} />
</Container>
</IsSignedInContext.Provider>
</ConfigContext.Provider>
2022-04-25 15:15:17 +02:00
)}
</GlobalLoadingContext.Provider>
</ModalsProvider>
</NotificationsProvider>
</ThemeProvider>
</MantineProvider>
);
}
export default App;
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => ({
colorScheme: getCookie("mantine-color-scheme", ctx) || "light",
});