Add ThemeProvider
This commit is contained in:
parent
b0fbf19249
commit
846df09e46
1 changed files with 22 additions and 21 deletions
|
|
@ -1,42 +1,43 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react"
|
||||||
import { getCookie } from "cookies-next";
|
import { getCookie } from "cookies-next"
|
||||||
import { appWithTranslation } from "next-i18next";
|
import { appWithTranslation } from "next-i18next"
|
||||||
|
import { ThemeProvider } from "next-themes"
|
||||||
|
|
||||||
import type { AppProps } from "next/app";
|
import type { AppProps } from "next/app"
|
||||||
import Layout from "~components/Layout";
|
import Layout from "~components/Layout"
|
||||||
|
|
||||||
import { accountState } from "~utils/accountState";
|
import { accountState } from "~utils/accountState"
|
||||||
|
|
||||||
import "../styles/globals.scss";
|
import "../styles/globals.scss"
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
function MyApp({ Component, pageProps }: AppProps) {
|
||||||
const cookie = getCookie("account");
|
const cookie = getCookie("account")
|
||||||
const cookieData: AccountCookie = cookie
|
const cookieData: AccountCookie = cookie ? JSON.parse(cookie as string) : null
|
||||||
? JSON.parse(cookie as string)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
console.log(`Logged in as user "${cookieData.username}"`);
|
console.log(`Logged in as user "${cookieData.username}"`)
|
||||||
|
|
||||||
accountState.account.authorized = true;
|
accountState.account.authorized = true
|
||||||
accountState.account.user = {
|
accountState.account.user = {
|
||||||
id: cookieData.userId,
|
id: cookieData.userId,
|
||||||
username: cookieData.username,
|
username: cookieData.username,
|
||||||
picture: "",
|
picture: "",
|
||||||
element: "",
|
element: "",
|
||||||
gender: 0,
|
gender: 0,
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`You are not currently logged in.`);
|
console.log(`You are not currently logged in.`)
|
||||||
}
|
}
|
||||||
}, [cookie, cookieData]);
|
}, [cookie, cookieData])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<ThemeProvider>
|
||||||
<Component {...pageProps} />
|
<Layout>
|
||||||
</Layout>
|
<Component {...pageProps} />
|
||||||
);
|
</Layout>
|
||||||
|
</ThemeProvider>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default appWithTranslation(MyApp);
|
export default appWithTranslation(MyApp)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue