From 988ffbf7746d113c8e8596e4c97cf3d4feb3b643 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Wed, 1 Oct 2025 21:48:54 +0200 Subject: [PATCH] refactor: remove automatic theme synchronization in UserPreferencesContext - Eliminated automatic synchronization of user preferences with the theme from ThemeContext, simplifying the logic. - Updated related useEffect hooks to reflect this change, ensuring that ThemeContext remains the source of truth for theme management. --- src/contexts/UserPreferencesContext.tsx | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/contexts/UserPreferencesContext.tsx b/src/contexts/UserPreferencesContext.tsx index eda5506..357db6d 100644 --- a/src/contexts/UserPreferencesContext.tsx +++ b/src/contexts/UserPreferencesContext.tsx @@ -77,7 +77,7 @@ const defaultPreferences: UserPreferences = { export function UserPreferencesProvider({ children, initialPreferences }: UserPreferencesProviderProps) { const [preferences, setPreferences] = useState(initialPreferences || defaultPreferences); const [isPending, startTransition] = useTransition(); - const { theme, toggleTheme: themeToggleTheme, setTheme: themeSetTheme } = useTheme(); + const { toggleTheme: themeToggleTheme, setTheme: themeSetTheme } = useTheme(); const { status } = useSession(); // Fonction pour charger les préférences côté client @@ -90,16 +90,13 @@ export function UserPreferencesProvider({ children, initialPreferences }: UserPr const result = await response.json(); if (result.success) { setPreferences(result.data); - // Synchroniser le thème avec le ThemeContext - if (result.data.viewPreferences.theme !== theme) { - themeSetTheme(result.data.viewPreferences.theme); - } + // Ne plus synchroniser automatiquement le thème - ThemeContext est la source de vérité } } } catch (error) { console.error('Erreur lors du chargement des préférences:', error); } - }, [status, theme, themeSetTheme]); + }, [status]); // Recharger les préférences quand la session change (login/logout) useEffect(() => { @@ -111,15 +108,7 @@ export function UserPreferencesProvider({ children, initialPreferences }: UserPr } }, [status, loadUserPreferences]); - // Synchroniser les préférences avec le thème actuel du ThemeContext - useEffect(() => { - if (preferences.viewPreferences.theme !== theme) { - setPreferences(prev => ({ - ...prev, - viewPreferences: { ...prev.viewPreferences, theme } - })); - } - }, [theme, preferences.viewPreferences.theme]); + // Ne plus synchroniser automatiquement - ThemeContext est la source de vérité // === KANBAN FILTERS ===