client: Use system theme (#60)

Use resolvedTheme theme from next-theme
This commit is contained in:
Joaquin "Florius" Azcarate 2022-04-01 22:36:03 +02:00 committed by GitHub
parent e3e9d993f2
commit dee06fab90
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -8,11 +8,11 @@ import { useTheme } from 'next-themes'
const Controls = () => {
const [mounted, setMounted] = useState(false)
const { theme, setTheme } = useTheme()
const { resolvedTheme, setTheme } = useTheme()
useEffect(() => setMounted(true), [])
if (!mounted) return null
const switchThemes = () => {
if (theme === 'dark') {
if (resolvedTheme === 'dark') {
setTheme('light')
} else {
setTheme('dark')
@ -26,7 +26,7 @@ const Controls = () => {
h="28px"
pure
onChange={switchThemes}
value={theme}
value={resolvedTheme}
>
<Select.Option value="light">
<span className={styles.selectContent}>

View file

@ -39,7 +39,7 @@ const Header = () => {
const { signedIn: isSignedIn, signout } = useSignedIn()
const userData = useUserData();
const [pages, setPages] = useState<Tab[]>([])
const { setTheme, theme } = useTheme()
const { setTheme, resolvedTheme } = useTheme()
useEffect(() => {
setBodyHidden(expanded)
@ -63,9 +63,9 @@ const Header = () => {
name: isMobile ? "Change theme" : "",
onClick: function () {
if (typeof window !== 'undefined')
setTheme(theme === 'light' ? 'dark' : 'light');
setTheme(resolvedTheme === 'light' ? 'dark' : 'light');
},
icon: theme === 'light' ? <MoonIcon /> : <SunIcon />,
icon: resolvedTheme === 'light' ? <MoonIcon /> : <SunIcon />,
value: "theme",
}
]
@ -133,7 +133,7 @@ const Header = () => {
}
// TODO: investigate deps causing infinite loop
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isMobile, isSignedIn, theme, userData])
}, [isMobile, isSignedIn, resolvedTheme, userData])
const onTabChange = useCallback((tab: string) => {
if (typeof window === 'undefined') return