From b7a4a4b800ec135b0d73316f55e9b032bc5a6bae Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 26 Nov 2024 14:59:05 -0800 Subject: [PATCH] Set default system mode as initial state --- apps/gitness/src/framework/context/ThemeContext.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/gitness/src/framework/context/ThemeContext.tsx b/apps/gitness/src/framework/context/ThemeContext.tsx index 48dbc587c..248361308 100644 --- a/apps/gitness/src/framework/context/ThemeContext.tsx +++ b/apps/gitness/src/framework/context/ThemeContext.tsx @@ -27,11 +27,9 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) { setTheme: state.setTheme })) - const [systemMode, setSystemMode] = useState(ModeType.Dark) + const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)') + const [systemMode, setSystemMode] = useState(mediaQuery.matches ? ModeType.Dark : ModeType.Light) useEffect(() => { - const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)') - setSystemMode(mediaQuery.matches ? ModeType.Dark : ModeType.Light) - const updateSystemTheme = () => { setSystemMode(mediaQuery.matches ? ModeType.Dark : ModeType.Light) }