Tell ThemeProvider whether to use system theme
This commit is contained in:
parent
d5244a49d6
commit
a69ae169fa
1 changed files with 8 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { useEffect } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { getCookie, getCookies } from 'cookies-next'
|
import { getCookie, getCookies } from 'cookies-next'
|
||||||
import { appWithTranslation } from 'next-i18next'
|
import { appWithTranslation } from 'next-i18next'
|
||||||
import { ThemeProvider } from 'next-themes'
|
import { ThemeProvider, useTheme } 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'
|
||||||
|
|
@ -20,12 +20,15 @@ function MyApp({ Component, pageProps }: AppProps) {
|
||||||
user: userCookie ? JSON.parse(userCookie as string) : undefined,
|
user: userCookie ? JSON.parse(userCookie as string) : undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [useSystem, setUseSystem] = useState(
|
||||||
|
cookieData.user?.theme === 'system'
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setUserToken()
|
setUserToken()
|
||||||
|
|
||||||
if (accountCookie) {
|
if (accountCookie) {
|
||||||
console.log(`Logged in as user "${cookieData.user}"`)
|
console.log(`Logged in as user "${cookieData.account.username}"`)
|
||||||
console.log(cookieData.account, cookieData.user)
|
|
||||||
|
|
||||||
accountState.account.authorized = true
|
accountState.account.authorized = true
|
||||||
accountState.account.user = {
|
accountState.account.user = {
|
||||||
|
|
@ -43,7 +46,7 @@ function MyApp({ Component, pageProps }: AppProps) {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider>
|
<ThemeProvider enableSystem={useSystem}>
|
||||||
<Layout>
|
<Layout>
|
||||||
<Component {...pageProps} />
|
<Component {...pageProps} />
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue