From 9a7246f55ac4eafde1f97f3c04dc67004e48a324 Mon Sep 17 00:00:00 2001 From: fullsizemalt <106900403+fullsizemalt@users.noreply.github.com> Date: Fri, 26 Dec 2025 21:45:32 -0800 Subject: [PATCH] Add theme persistence - syncs with user preferences --- frontend/components/theme-toggle.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 (