2022-04-24 22:36:47 +02:00
|
|
|
import { GetServerSidePropsContext } from 'next';
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { AppProps } from 'next/app';
|
2022-07-22 16:20:47 +02:00
|
|
|
import { getCookie, setCookie } from 'cookies-next';
|
2022-04-24 22:36:47 +02:00
|
|
|
import Head from 'next/head';
|
2022-06-08 15:36:54 +00:00
|
|
|
import { MantineProvider, ColorScheme, ColorSchemeProvider, MantineTheme } from '@mantine/core';
|
2022-04-24 22:36:47 +02:00
|
|
|
import { NotificationsProvider } from '@mantine/notifications';
|
2022-05-17 04:19:59 +02:00
|
|
|
import { useHotkeys } from '@mantine/hooks';
|
2022-08-07 12:14:37 +02:00
|
|
|
import { ModalsProvider } from '@mantine/modals';
|
2022-06-08 14:58:32 +00:00
|
|
|
import { ConfigProvider } from '../tools/state';
|
2022-05-10 18:57:41 +02:00
|
|
|
import { theme } from '../tools/theme';
|
2022-06-08 14:58:32 +00:00
|
|
|
import { ColorTheme } from '../tools/color';
|
2022-08-18 21:46:46 +02:00
|
|
|
import { I18nextProvider } from 'react-i18next';
|
|
|
|
|
import { loadI18n } from '../translations/i18n';
|
|
|
|
|
import { TranslationProvider } from '../providers/translation.provider';
|
2022-04-24 22:36:47 +02:00
|
|
|
|
2022-06-08 14:58:32 +00:00
|
|
|
export default function App(this: any, props: AppProps & { colorScheme: ColorScheme }) {
|
2022-04-24 22:36:47 +02:00
|
|
|
const { Component, pageProps } = props;
|
2022-05-17 04:19:59 +02:00
|
|
|
const [colorScheme, setColorScheme] = useState<ColorScheme>(props.colorScheme);
|
2022-04-24 22:36:47 +02:00
|
|
|
|
2022-06-08 15:36:54 +00:00
|
|
|
const [primaryColor, setPrimaryColor] = useState<MantineTheme['primaryColor']>('red');
|
|
|
|
|
const [secondaryColor, setSecondaryColor] = useState<MantineTheme['primaryColor']>('orange');
|
|
|
|
|
const [primaryShade, setPrimaryShade] = useState<MantineTheme['primaryShade']>(6);
|
2022-06-08 14:58:32 +00:00
|
|
|
const colorTheme = {
|
|
|
|
|
primaryColor,
|
|
|
|
|
secondaryColor,
|
|
|
|
|
setPrimaryColor,
|
|
|
|
|
setSecondaryColor,
|
2022-06-08 15:36:54 +00:00
|
|
|
primaryShade,
|
|
|
|
|
setPrimaryShade,
|
2022-06-08 14:58:32 +00:00
|
|
|
};
|
|
|
|
|
|
2022-04-24 22:36:47 +02:00
|
|
|
const toggleColorScheme = (value?: ColorScheme) => {
|
|
|
|
|
const nextColorScheme = value || (colorScheme === 'dark' ? 'light' : 'dark');
|
|
|
|
|
setColorScheme(nextColorScheme);
|
2022-07-22 16:20:47 +02:00
|
|
|
setCookie('color-scheme', nextColorScheme, { maxAge: 60 * 60 * 24 * 30 });
|
2022-04-24 22:36:47 +02:00
|
|
|
};
|
2022-05-15 12:42:53 +02:00
|
|
|
useHotkeys([['mod+J', () => toggleColorScheme()]]);
|
2022-04-24 22:36:47 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Head>
|
|
|
|
|
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
|
|
|
|
|
</Head>
|
|
|
|
|
|
|
|
|
|
<ColorSchemeProvider colorScheme={colorScheme} toggleColorScheme={toggleColorScheme}>
|
2022-06-08 14:58:32 +00:00
|
|
|
<ColorTheme.Provider value={colorTheme}>
|
|
|
|
|
<MantineProvider
|
|
|
|
|
theme={{
|
|
|
|
|
...theme,
|
2022-08-08 15:43:04 +02:00
|
|
|
components: {
|
|
|
|
|
Checkbox: {
|
|
|
|
|
styles: {
|
|
|
|
|
input: { cursor: 'pointer' },
|
|
|
|
|
label: { cursor: 'pointer' },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Switch: {
|
|
|
|
|
styles: {
|
|
|
|
|
input: { cursor: 'pointer' },
|
|
|
|
|
label: { cursor: 'pointer' },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-06-08 14:58:32 +00:00
|
|
|
primaryColor,
|
2022-06-08 15:36:54 +00:00
|
|
|
primaryShade,
|
2022-06-08 14:58:32 +00:00
|
|
|
colorScheme,
|
|
|
|
|
}}
|
|
|
|
|
withGlobalStyles
|
|
|
|
|
withNormalizeCSS
|
|
|
|
|
>
|
|
|
|
|
<NotificationsProvider limit={4} position="bottom-left">
|
2022-08-07 12:14:37 +02:00
|
|
|
<ModalsProvider>
|
|
|
|
|
<ConfigProvider>
|
2022-08-18 21:46:46 +02:00
|
|
|
<TranslationProvider>
|
|
|
|
|
<Component {...pageProps} />
|
|
|
|
|
</TranslationProvider>
|
2022-08-07 12:14:37 +02:00
|
|
|
</ConfigProvider>
|
|
|
|
|
</ModalsProvider>
|
2022-06-08 14:58:32 +00:00
|
|
|
</NotificationsProvider>
|
|
|
|
|
</MantineProvider>
|
|
|
|
|
</ColorTheme.Provider>
|
2022-04-24 22:36:47 +02:00
|
|
|
</ColorSchemeProvider>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => ({
|
2022-05-12 19:28:10 +02:00
|
|
|
colorScheme: getCookie('color-scheme', ctx) || 'light',
|
2022-04-24 22:36:47 +02:00
|
|
|
});
|