From 1b69f7841c9d932b1aabac3a4a178d60fb572073 Mon Sep 17 00:00:00 2001 From: qinluhe Date: Wed, 3 Jul 2024 14:56:43 +0800 Subject: [PATCH] fix: save the dark mode in local storage --- .../appflowy_web_app/src/components/app/useAppThemeMode.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/appflowy_web_app/src/components/app/useAppThemeMode.ts b/frontend/appflowy_web_app/src/components/app/useAppThemeMode.ts index 6f90968590..69823f0a2f 100644 --- a/frontend/appflowy_web_app/src/components/app/useAppThemeMode.ts +++ b/frontend/appflowy_web_app/src/components/app/useAppThemeMode.ts @@ -9,7 +9,11 @@ export const ThemeModeContext = createContext< >(undefined); export function useAppThemeMode() { - const [isDark, setIsDark] = useState(false); + const [isDark, setIsDark] = useState(() => { + const darkMode = localStorage.getItem('dark-mode'); + + return darkMode === 'true'; + }); useEffect(() => { function detectColorScheme() { @@ -28,6 +32,7 @@ export function useAppThemeMode() { useEffect(() => { document.documentElement.setAttribute('data-dark-mode', isDark ? 'true' : 'false'); + localStorage.setItem('dark-mode', isDark ? 'true' : 'false'); }, [isDark]); return {