feat: static generation
This commit is contained in:
1 parent
99255f4f13
commit
25866b9eb9
12 files changed
+56
-72
No files matched your search
@@ -1,34 +0,0 @@
|
||||
import { createContext, Dispatch, FC, ReactNode, SetStateAction, useEffect, useState } from 'react';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export const ThemeContext = createContext<[Theme, Dispatch<SetStateAction<Theme>>]>([
|
||||
Cookies.get('theme') as Theme,
|
||||
() => null
|
||||
]);
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
theme?: Theme;
|
||||
}
|
||||
|
||||
const Provider: FC<Props> = ({ children, theme: initialTheme }) => {
|
||||
const state = useState<Theme>((Cookies.get('theme') || initialTheme) as Theme);
|
||||
|
||||
const [theme, setTheme] = state;
|
||||
|
||||
useEffect(() => {
|
||||
if (!theme) {
|
||||
return setTheme(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
||||
}
|
||||
|
||||
document.documentElement.setAttribute('data-mode', theme);
|
||||
document
|
||||
.querySelector('meta[name="theme-color"]')
|
||||
?.setAttribute('content', theme === 'dark' ? 'hsl(222.2 84% 4.9%)' : 'white');
|
||||
Cookies.set('theme', theme);
|
||||
}, [theme, setTheme]);
|
||||
|
||||
return <ThemeContext.Provider value={state}>{children}</ThemeContext.Provider>;
|
||||
};
|
||||
|
||||
export default Provider;
|
||||
+3
-5
@@ -5,24 +5,22 @@ import ModalContainer from 'react-modal-promise';
|
||||
import { QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental';
|
||||
import { ThemeProvider } from 'next-themes';
|
||||
|
||||
import { Toaster } from '@/components/ui/toaster';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import ThemeProvider from './Theme';
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
theme?: Theme;
|
||||
}
|
||||
|
||||
const Providers: FC<Props> = ({ children, theme }) => {
|
||||
const Providers: FC<Props> = ({ children }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ReactQueryStreamedHydration>
|
||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||
<ThemeProvider attribute='data-mode'>{children}</ThemeProvider>
|
||||
</ReactQueryStreamedHydration>
|
||||
<ModalContainer exitTimeout={0} enterTimeout={0} />
|
||||
<Toaster />
|
||||
|
||||
Reference in new issue
Block a user