mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-05-04 13:22:58 +02:00
Add dark mode with theme toggle
- Add dark theme CSS variables - Theme toggle button in navbar and auth pages - Persist theme preference in localStorage - Update chart colors for dark mode - Auto-detect theme changes via MutationObserver Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a2b0c2cc65
commit
4ef61517e3
5 changed files with 165 additions and 22 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { useEffect } from 'react';
|
||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { AuthProvider, useAuth } from './context/AuthContext';
|
||||
import Login from './pages/Login';
|
||||
|
|
@ -5,6 +6,16 @@ import Register from './pages/Register';
|
|||
import Dashboard from './pages/Dashboard';
|
||||
import ProductDetail from './pages/ProductDetail';
|
||||
|
||||
function ThemeInitializer({ children }: { children: React.ReactNode }) {
|
||||
useEffect(() => {
|
||||
const saved = localStorage.getItem('theme');
|
||||
if (saved) {
|
||||
document.documentElement.setAttribute('data-theme', saved);
|
||||
}
|
||||
}, []);
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
||||
const { user, isLoading } = useAuth();
|
||||
|
||||
|
|
@ -97,10 +108,12 @@ function AppRoutes() {
|
|||
|
||||
export default function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<AuthProvider>
|
||||
<AppRoutes />
|
||||
</AuthProvider>
|
||||
</BrowserRouter>
|
||||
<ThemeInitializer>
|
||||
<BrowserRouter>
|
||||
<AuthProvider>
|
||||
<AppRoutes />
|
||||
</AuthProvider>
|
||||
</BrowserRouter>
|
||||
</ThemeInitializer>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue