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.
This commit is contained in:
@@ -77,7 +77,7 @@ const defaultPreferences: UserPreferences = {
|
||||
export function UserPreferencesProvider({ children, initialPreferences }: UserPreferencesProviderProps) {
|
||||
const [preferences, setPreferences] = useState<UserPreferences>(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 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user