Files
towercontrol/src/hooks/useBackgroundCycle.ts
Julien Froidefond 10c1f811ce feat: integrate ToastProvider and enhance theme management
- Added `ToastProvider` to `RootLayout` for improved user feedback on theme changes.
- Updated `ThemeProvider` to display toast notifications with theme names and icons upon theme changes.
- Refactored theme-related imports to streamline code and improve maintainability.
- Simplified background cycling logic in `useBackgroundCycle` to utilize centralized background definitions.
- Cleaned up unused background definitions in `BackgroundContext` for better clarity and performance.
2025-10-02 17:24:37 +02:00

29 lines
1.0 KiB
TypeScript

'use client';
import { useUserPreferences } from '@/contexts/UserPreferencesContext';
import { useToast } from '@/components/ui/Toast';
import { BACKGROUND_NAMES, TOAST_ICONS, getNextBackground } from '@/lib/ui-config';
export function useBackgroundCycle() {
const { preferences, updateViewPreferences } = useUserPreferences();
const { showToast } = useToast();
const cycleBackground = () => {
const currentBackground = preferences?.viewPreferences?.backgroundImage;
const customImages = preferences?.viewPreferences?.customImages || [];
const nextBackground = getNextBackground(currentBackground || 'none', customImages);
const backgroundImage = nextBackground === 'none' ? undefined : nextBackground;
updateViewPreferences({ backgroundImage });
// Afficher le toast avec le nom du background
const backgroundName = BACKGROUND_NAMES[nextBackground] || 'Image personnalisée';
showToast(`Background: ${backgroundName}`, 2000, TOAST_ICONS.background);
};
return {
cycleBackground
};
}