diff --git a/Frontend/src/App.jsx b/Frontend/src/App.jsx index 0706fb2..4e17baa 100644 --- a/Frontend/src/App.jsx +++ b/Frontend/src/App.jsx @@ -19,20 +19,21 @@ function ProtectedRoute({ children }) { } function App() { - const { theme } = useStore(); + const { theme, setTheme } = useStore(); useEffect(() => { const root = window.document.documentElement; root.classList.remove('light', 'dark'); - if (theme === 'system' || theme === 'auto') { - const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; - root.classList.add(systemTheme); - return; + let effectiveTheme = theme; + if (theme !== 'light' && theme !== 'dark') { + effectiveTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; + // Normalise the stored theme so future toggles are predictable + setTheme(effectiveTheme); } - root.classList.add(theme); - }, [theme]); + root.classList.add(effectiveTheme); + }, [theme, setTheme]); return ( diff --git a/Frontend/src/components/Layout.jsx b/Frontend/src/components/Layout.jsx index 59cd031..5a58e03 100644 --- a/Frontend/src/components/Layout.jsx +++ b/Frontend/src/components/Layout.jsx @@ -9,12 +9,13 @@ import { LogOut, Menu, X, - Bell, - ChevronDown + ChevronDown, + Sun, + Moon } from 'lucide-react'; export default function Layout({ children }) { - const { user, logout, notifications, unreadCount } = useStore(); + const { user, logout, theme, setTheme } = useStore(); const navigate = useNavigate(); const location = useLocation(); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); @@ -25,6 +26,11 @@ export default function Layout({ children }) { navigate('/login'); }; + const toggleTheme = () => { + // Simple, predictable toggle between light and dark + setTheme(theme === 'dark' ? 'light' : 'dark'); + }; + const navItems = [ { icon: LayoutDashboard, label: 'Dashboard', path: '/' }, { icon: Users, label: 'My Groups', path: '/groups' }, @@ -33,15 +39,15 @@ export default function Layout({ children }) { ]; return ( -
+
{/* Sidebar (Desktop) */} -