_app.page.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import type { ReactElement, ReactNode } from 'react';
  2. import React, { useEffect } from 'react';
  3. import type { NextPage } from 'next';
  4. import { appWithTranslation } from 'next-i18next';
  5. import type { AppProps } from 'next/app';
  6. import { SWRConfig } from 'swr';
  7. import * as nextI18nConfig from '^/config/next-i18next.config';
  8. import { GlobalFonts } from '~/components/FontFamily/GlobalFonts';
  9. import {
  10. useAppTitle, useConfidential, useGrowiVersion, useSiteUrl, useIsDefaultLogo, useForcedColorScheme,
  11. } from '~/stores/context';
  12. import { swrGlobalConfiguration } from '~/utils/swr-utils';
  13. import type { CommonProps } from './utils/commons';
  14. import { registerTransformerForObjectId } from './utils/objectid-transformer';
  15. import '~/styles/prebuilt/vendor.css';
  16. import '~/styles/style-app.scss';
  17. // eslint-disable-next-line @typescript-eslint/ban-types
  18. export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
  19. getLayout?: (page: ReactElement) => ReactNode,
  20. }
  21. type GrowiAppProps = AppProps & {
  22. Component: NextPageWithLayout,
  23. };
  24. // register custom serializer
  25. registerTransformerForObjectId();
  26. function GrowiApp({ Component, pageProps }: GrowiAppProps): JSX.Element {
  27. useEffect(() => {
  28. import('bootstrap/dist/js/bootstrap');
  29. }, []);
  30. const commonPageProps = pageProps as CommonProps;
  31. useAppTitle(commonPageProps.appTitle);
  32. useSiteUrl(commonPageProps.siteUrl);
  33. useConfidential(commonPageProps.confidential);
  34. useGrowiVersion(commonPageProps.growiVersion);
  35. useIsDefaultLogo(commonPageProps.isDefaultLogo);
  36. useForcedColorScheme(commonPageProps.forcedColorScheme);
  37. // Use the layout defined at the page level, if available
  38. const getLayout = Component.getLayout ?? (page => page);
  39. return (
  40. <>
  41. <GlobalFonts />
  42. <SWRConfig value={swrGlobalConfiguration}>
  43. {getLayout(<Component {...pageProps} />)}
  44. </SWRConfig>
  45. </>
  46. );
  47. }
  48. export default appWithTranslation(GrowiApp, nextI18nConfig);