feat: ajout de la gestion des doubles pages pour le lecteur, incluant des paramètres de détection automatique, des modes d'affichage et des préférences sauvegardées. Amélioration de l'interface utilisateur pour intégrer ces nouvelles fonctionnalités.

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-07-06 15:55:55 +02:00
parent a6ca8a2c9a
commit 5a5569cf2c
9 changed files with 1150 additions and 63 deletions

View File

@@ -13,7 +13,14 @@ export const useReaderStore = defineStore('reader', {
error: null,
pages: [],
totalPages: 0,
loadedPages: new Set() // Garder une trace des pages déjà chargées
loadedPages: new Set(), // Garder une trace des pages déjà chargées
// Paramètres pour les doubles pages
doublePageSettings: {
autoDetect: true,
mobileMode: 'rotate', // 'rotate', 'scroll', 'normal'
detectionThreshold: 1.2 // Ratio largeur/hauteur pour détecter une double page
}
}),
getters: {
@@ -21,7 +28,24 @@ export const useReaderStore = defineStore('reader', {
isLastPage: state => state.currentPage === state.totalPages - 1,
currentPageData: state => state.pages[state.currentPage],
hasPreviousChapter: state => Boolean(state.currentChapter?.navigation?.previousChapter),
hasNextChapter: state => Boolean(state.currentChapter?.navigation?.nextChapter)
hasNextChapter: state => Boolean(state.currentChapter?.navigation?.nextChapter),
// Getters pour les doubles pages
effectiveDoublePageMode: (state) => {
// Si la détection automatique est désactivée, retourner 'normal'
if (!state.doublePageSettings.autoDetect) {
return 'normal';
}
return state.doublePageSettings.mobileMode;
},
// Préférences sauvegardées dans localStorage
savedPreferences: (state) => ({
readingMode: state.readingMode,
readingDirection: state.readingDirection,
zoom: state.zoom,
doublePageSettings: state.doublePageSettings
})
},
actions: {
@@ -145,6 +169,7 @@ export const useReaderStore = defineStore('reader', {
if (mode === this.readingMode) return;
this.readingMode = mode;
this.savePreferences();
// S'assurer que la page courante est chargée
await this.loadPageData(this.currentPage);
@@ -157,10 +182,44 @@ export const useReaderStore = defineStore('reader', {
setReadingDirection(direction) {
this.readingDirection = direction;
this.savePreferences();
},
setZoom(level) {
this.zoom = level;
setZoom(zoom) {
this.zoom = Math.max(0.5, Math.min(2, zoom));
this.savePreferences();
},
// Nouvelles actions pour les doubles pages
setDoublePageMode(mode) {
if (['rotate', 'scroll', 'normal'].includes(mode)) {
this.doublePageSettings.mobileMode = mode;
this.savePreferences();
}
},
setDoublePageAutoDetect(enabled) {
this.doublePageSettings.autoDetect = enabled;
this.savePreferences();
},
setDoublePageDetectionThreshold(threshold) {
this.doublePageSettings.detectionThreshold = Math.max(1.0, Math.min(3.0, threshold));
this.savePreferences();
},
updateDoublePageSettings(settings) {
this.doublePageSettings = {
...this.doublePageSettings,
...settings
};
this.savePreferences();
},
async goToNextChapter() {
if (this.currentChapter?.navigation?.nextChapter) {
await this.loadChapter(this.currentChapter.navigation.nextChapter);
}
},
async goToPreviousChapter() {
@@ -175,10 +234,60 @@ export const useReaderStore = defineStore('reader', {
}
},
async goToNextChapter() {
if (this.currentChapter?.navigation?.nextChapter) {
await this.loadChapter(this.currentChapter.navigation.nextChapter);
// Gestion de la persistance des préférences
savePreferences() {
try {
const preferences = {
readingMode: this.readingMode,
readingDirection: this.readingDirection,
zoom: this.zoom,
doublePageSettings: this.doublePageSettings
};
localStorage.setItem('mangarr-reader-preferences', JSON.stringify(preferences));
} catch (error) {
console.error('Erreur lors de la sauvegarde des préférences:', error);
}
},
loadPreferences() {
try {
const stored = localStorage.getItem('mangarr-reader-preferences');
if (stored) {
const preferences = JSON.parse(stored);
// Appliquer les préférences sauvegardées
if (preferences.readingMode) this.readingMode = preferences.readingMode;
if (preferences.readingDirection) this.readingDirection = preferences.readingDirection;
if (typeof preferences.zoom === 'number') this.zoom = preferences.zoom;
// Migration: si l'ancien doublePageMode existe, le migrer vers mobileMode
if (preferences.doublePageMode && ['rotate', 'scroll', 'normal'].includes(preferences.doublePageMode)) {
this.doublePageSettings.mobileMode = preferences.doublePageMode;
}
if (preferences.doublePageSettings) {
this.doublePageSettings = {
...this.doublePageSettings,
...preferences.doublePageSettings
};
}
}
} catch (error) {
console.error('Erreur lors du chargement des préférences:', error);
}
},
// Réinitialiser les préférences
resetPreferences() {
this.readingMode = 'single';
this.readingDirection = 'ltr';
this.zoom = 1;
this.doublePageSettings = {
autoDetect: true,
mobileMode: 'rotate',
detectionThreshold: 1.2
};
this.savePreferences();
}
}
});