From 6425c155cef5f439775c17d2edeb9927021c69c9 Mon Sep 17 00:00:00 2001 From: nmemmert Date: Thu, 15 Jan 2026 15:00:13 -0500 Subject: [PATCH] fix: implement working theme selector with localStorage persistence --- src/components/ClientLayout.tsx | 2 +- src/components/SettingsPage.tsx | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/components/ClientLayout.tsx b/src/components/ClientLayout.tsx index 72a3522..59a5895 100644 --- a/src/components/ClientLayout.tsx +++ b/src/components/ClientLayout.tsx @@ -10,7 +10,7 @@ export default function ClientLayout({ children: React.ReactNode; }) { return ( - + {children} ('dark'); + + useEffect(() => { + setMounted(true); + // Get the current theme from localStorage or system preference + const stored = localStorage.getItem('theme'); + if (stored) { + setCurrentTheme(stored); + } else if (theme) { + setCurrentTheme(theme); + } + }, [theme]); + + const handleThemeChange = (newTheme: string) => { + setCurrentTheme(newTheme); + localStorage.setItem('theme', newTheme); + setTheme(newTheme); + + // Update the HTML element immediately + const html = document.documentElement; + if (newTheme === 'dark' || (newTheme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) { + html.classList.add('dark'); + } else { + html.classList.remove('dark'); + } + }; return (
@@ -54,9 +81,9 @@ export default function SettingsPage({ userEmail }: SettingsPageProps) { {['light', 'dark', 'system'].map(t => (