From d08f63f50c07febd395ebf761ed6c85c88052ede Mon Sep 17 00:00:00 2001 From: abhishekbhakat Date: Fri, 19 Dec 2025 20:41:07 +0530 Subject: [PATCH] feat: Implement theme state management and enhance theme toggle button with dynamic icons and accessibility. --- frontend/src/pages/Dashboard.tsx | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index 924001b..0c36c42 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -12,6 +12,9 @@ export function Dashboard() { const navigate = useNavigate() const [user, setUser] = useState(null) const [loading, setLoading] = useState(true) + const [theme, setTheme] = useState(() => + document.documentElement.getAttribute('data-theme') || 'light' + ) useEffect(() => { // First get auth info, then fetch full user profile for name @@ -43,6 +46,13 @@ export function Dashboard() { navigate('/login') } + const toggleTheme = () => { + const newTheme = theme === 'dark' ? 'light' : 'dark' + document.documentElement.setAttribute('data-theme', newTheme) + localStorage.setItem('theme', newTheme) + setTheme(newTheme) + } + if (loading) { return
Loading...
} @@ -51,13 +61,6 @@ export function Dashboard() { return null } - const toggleTheme = () => { - const current = document.documentElement.getAttribute('data-theme') - const newTheme = current === 'dark' ? 'light' : 'dark' - document.documentElement.setAttribute('data-theme', newTheme) - localStorage.setItem('theme', newTheme) - } - // Display name or username fallback const displayName = user.name || user.username @@ -69,8 +72,13 @@ export function Dashboard() {

zhealth

-
+