diff --git a/src/app/components/ExchangeRateViewer.js b/src/app/components/ExchangeRateViewer.js index 322cbb9..ba6737b 100644 --- a/src/app/components/ExchangeRateViewer.js +++ b/src/app/components/ExchangeRateViewer.js @@ -76,6 +76,42 @@ function getActivePreset(startDate, endDate) { return null; } +function applyTheme(value) { + const root = document.documentElement; + if (value === "system") { + root.removeAttribute("data-theme"); + } else { + root.setAttribute("data-theme", value); + } +} + +const THEME_CYCLE = ["system", "light", "dark"]; +const THEME_LABELS = { system: "System", light: "Light", dark: "Dark" }; + +function SunIcon() { + return ( + + ); +} + +function MoonIcon() { + return ( + + ); +} + +function SystemIcon() { + return ( + + ); +} + // Inline SVG icons (16x16) to avoid adding an icon library dependency function FetchIcon() { return ( @@ -113,6 +149,7 @@ export default function ExchangeRateViewer() { const [results, setResults] = useState([]); const [hasFetched, setHasFetched] = useState(false); const [progress, setProgress] = useState(null); + const [theme, setTheme] = useState("system"); // Restore saved settings on client mount — URL params take priority over localStorage const [hydrated, setHydrated] = useState(false); @@ -125,6 +162,9 @@ export default function ExchangeRateViewer() { if (saved.startDate) setStartDate(saved.startDate); if (saved.endDate) setEndDate(saved.endDate); } + const savedTheme = localStorage.getItem("theme") || "system"; + setTheme(savedTheme); + applyTheme(savedTheme); setHydrated(true); }, []); @@ -249,11 +289,26 @@ export default function ExchangeRateViewer() { return (
- Fetch exchange rates from Vietnamese banks and export to CSV. -
++ Fetch exchange rates from Vietnamese banks and export to CSV. +
+