moonstream/frontend/pages/_app.js

86 wiersze
2.6 KiB
JavaScript
Czysty Zwykły widok Historia

2021-08-05 10:42:45 +00:00
import { React, useEffect, useState } from "react";
2021-07-13 11:35:46 +00:00
import "/styles/styles.css";
2021-08-05 10:38:42 +00:00
import "/styles/nprogress.css";
2021-07-13 11:35:46 +00:00
import "/styles/sidebar.css";
2021-07-20 11:36:59 +00:00
import "highlight.js/styles/github.css";
2021-08-05 10:38:42 +00:00
import "focus-visible/dist/focus-visible";
2021-11-01 13:55:29 +00:00
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
2021-07-13 11:35:46 +00:00
import dynamic from "next/dynamic";
2021-08-05 10:53:02 +00:00
import { QueryClient, QueryClientProvider } from "react-query";
2021-11-02 14:24:20 +00:00
import { ReactQueryDevtools } from "react-query/devtools";
2021-10-31 13:59:14 +00:00
import HeadLinks from "../src/components/HeadLinks";
import HeadSEO from "../src/components/HeadSEO";
2021-07-13 11:35:46 +00:00
const AppContext = dynamic(() => import("../src/AppContext"), {
ssr: false,
});
2021-08-05 15:01:02 +00:00
const DefaultLayout = dynamic(() => import("../src/layouts"), {
ssr: false,
});
2021-08-05 10:38:42 +00:00
import { useRouter } from "next/router";
import NProgress from "nprogress";
2021-08-26 13:18:48 +00:00
import { WHITE_LOGO_W_TEXT_URL } from "../src/core/constants";
2021-08-05 10:38:42 +00:00
export default function CachingApp({ Component, pageProps }) {
2021-08-05 11:02:53 +00:00
const [queryClient] = useState(new QueryClient());
2021-08-05 10:38:42 +00:00
const router = useRouter();
2021-11-03 18:47:44 +00:00
useEffect(() => {
if (
router.pathname !== "/entry-point" &&
window &&
localStorage.getItem("entry_point")
) {
localStorage.removeItem("entry_point");
}
}, [router]);
2021-08-05 10:38:42 +00:00
useEffect(() => {
2021-08-05 14:10:50 +00:00
const handleStart = () => {
2021-08-05 10:38:42 +00:00
NProgress.start();
};
const handleStop = () => {
NProgress.done();
};
2021-07-01 23:13:35 +00:00
2021-08-05 10:38:42 +00:00
router.events.on("routeChangeStart", handleStart);
router.events.on("routeChangeComplete", handleStop);
router.events.on("routeChangeError", handleStop);
2021-08-05 10:38:42 +00:00
return () => {
router.events.off("routeChangeStart", handleStart);
router.events.off("routeChangeComplete", handleStop);
router.events.off("routeChangeError", handleStop);
};
}, [router]);
const getLayout =
Component.getLayout || ((page) => <DefaultLayout>{page}</DefaultLayout>);
2021-07-13 11:35:46 +00:00
2021-08-26 13:18:48 +00:00
const headLinks = [
{ rel: "preload", as: "image", href: WHITE_LOGO_W_TEXT_URL },
];
pageProps.preloads && headLinks.push(...pageProps.preloads);
2021-08-05 10:38:42 +00:00
return (
<>
<style global jsx>{`
html,
body,
body > div:first-child,
div#__next,
div#__next > div {
height: 100% !important;
width: 100%;
overflow: hidden;
}
`}</style>
{pageProps.metaTags && <HeadSEO {...pageProps.metaTags} />}
2021-08-26 13:18:48 +00:00
<HeadLinks links={headLinks} />
2021-08-05 11:02:53 +00:00
<QueryClientProvider client={queryClient}>
2021-09-08 15:47:45 +00:00
<ReactQueryDevtools initialIsOpen={false} />
2021-08-05 10:38:42 +00:00
<AppContext>{getLayout(<Component {...pageProps} />)}</AppContext>
2021-08-05 10:53:02 +00:00
</QueryClientProvider>
2021-08-05 10:38:42 +00:00
</>
);
2021-07-01 23:13:35 +00:00
}