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.
This commit is contained in:
Julien Froidefond
2025-10-02 17:24:37 +02:00
parent 99377ee38d
commit 10c1f811ce
10 changed files with 405 additions and 189 deletions

View File

@@ -1,66 +1,25 @@
'use client';
import { useUserPreferences } from '@/contexts/UserPreferencesContext';
// Liste des backgrounds prédéfinis pour le cycle
const BACKGROUND_CYCLE = [
'none',
'theme-subtle',
'theme-primary',
'theme-accent',
'theme-success',
'theme-purple',
'theme-diagonal',
'theme-radial',
'theme-sunset',
'theme-ocean',
'theme-forest',
'theme-galaxy'
];
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 || [];
// Construire la liste complète des backgrounds (prédéfinis + personnalisés)
const allBackgrounds = [...BACKGROUND_CYCLE];
// Ajouter toutes les images personnalisées
customImages.forEach(url => {
if (!allBackgrounds.includes(url)) {
allBackgrounds.push(url);
}
});
const currentIndex = allBackgrounds.findIndex(bg => bg === currentBackground);
// Si on ne trouve pas l'index, c'est qu'on est sur "none" (undefined)
// Dans ce cas, on commence au début de la liste
let actualCurrentIndex = currentIndex;
if (currentIndex === -1) {
actualCurrentIndex = -1; // On est sur "none", on va commencer à l'index 0
}
const nextIndex = (actualCurrentIndex + 1) % allBackgrounds.length;
const nextBackground = allBackgrounds[nextIndex];
// Si c'est 'none', on met undefined
const nextBackground = getNextBackground(currentBackground || 'none', customImages);
const backgroundImage = nextBackground === 'none' ? undefined : nextBackground;
// Si on est sur "none" (undefined) et qu'on va vers "none", on va vers le suivant
if (currentBackground === undefined && nextBackground === 'none') {
const nextNextIndex = (nextIndex + 1) % allBackgrounds.length;
const nextNextBackground = allBackgrounds[nextNextIndex];
const finalBackgroundImage = nextNextBackground === 'none' ? undefined : nextNextBackground;
updateViewPreferences({ backgroundImage: finalBackgroundImage });
return;
}
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 {