diff --git a/frontend/components/theme-toggle.tsx b/frontend/components/theme-toggle.tsx index 0c2067d..dc7382c 100644 --- a/frontend/components/theme-toggle.tsx +++ b/frontend/components/theme-toggle.tsx @@ -4,15 +4,34 @@ import * as React from "react" import { Moon, Sun } from "lucide-react" import { useTheme } from "next-themes" import { Button } from "@/components/ui/button" +import { usePreferences } from "@/contexts/preferences-context" export function ThemeToggle() { const { theme, setTheme } = useTheme() + const { preferences, updatePreferences, loading: prefsLoading } = usePreferences() const [mounted, setMounted] = React.useState(false) React.useEffect(() => { setMounted(true) }, []) + // Sync theme from preferences when loaded + React.useEffect(() => { + if (!prefsLoading && preferences.theme && mounted) { + // Only sync if the preference is different from current theme + if (preferences.theme !== theme && preferences.theme !== "system") { + setTheme(preferences.theme) + } + } + }, [prefsLoading, preferences.theme, mounted]) + + const handleToggle = () => { + const newTheme = theme === "dark" ? "light" : "dark" + setTheme(newTheme) + // Persist to backend + updatePreferences({ theme: newTheme }) + } + if (!mounted) { return (