feat: ajout de la gestion des chapitres dans le store Manga avec des actions pour charger et mettre à jour la disponibilité des chapitres, intégration d'un écouteur Mercure pour les mises à jour en temps réel, et amélioration des composants d'interface utilisateur pour gérer les états de chargement et d'erreur.
This commit is contained in:
parent
e51712a800
commit
5928cfd5f0
@@ -28,6 +28,11 @@ export const useMangaStore = defineStore('manga', {
|
||||
// mais les données détaillées ne sont plus stockées ici.
|
||||
currentMangaId: null,
|
||||
|
||||
// --- Manga Chapters State ---
|
||||
mangaChapters: {},
|
||||
loadingChapters: false,
|
||||
chaptersError: null,
|
||||
|
||||
// --- Search State ---
|
||||
searchResults: [],
|
||||
loadingSearch: false,
|
||||
@@ -86,6 +91,60 @@ export const useMangaStore = defineStore('manga', {
|
||||
this.currentMangaId = null;
|
||||
},
|
||||
|
||||
// --- Chapters Actions ---
|
||||
async loadChapters(mangaId) {
|
||||
if (this.loadingChapters) return;
|
||||
this.loadingChapters = true;
|
||||
this.chaptersError = null;
|
||||
|
||||
try {
|
||||
const chaptersData = await mangaRepository.getChapters(mangaId);
|
||||
this.mangaChapters[mangaId] = chaptersData;
|
||||
} catch (err) {
|
||||
this.chaptersError = err.message;
|
||||
} finally {
|
||||
this.loadingChapters = false;
|
||||
}
|
||||
},
|
||||
|
||||
updateChapterAvailability(chapterId, isAvailable = true) {
|
||||
console.log(`Mise à jour du chapitre ${chapterId}, disponible: ${isAvailable}`);
|
||||
|
||||
// Pour chaque manga dans notre store
|
||||
Object.keys(this.mangaChapters).forEach(mangaId => {
|
||||
const chaptersObj = this.mangaChapters[mangaId];
|
||||
if (!chaptersObj || !chaptersObj.items) return;
|
||||
|
||||
const chapters = chaptersObj.items;
|
||||
|
||||
// Chercher le chapitre correspondant
|
||||
const chapterIndex = chapters.findIndex(chapter => chapter.id === chapterId);
|
||||
|
||||
// Si on trouve le chapitre, mettre à jour son état
|
||||
if (chapterIndex !== -1) {
|
||||
console.log(`Chapitre trouvé dans le manga ${mangaId}, index: ${chapterIndex}`);
|
||||
|
||||
// Important: créer une nouvelle référence pour que Vue détecte le changement
|
||||
const updatedChapter = {
|
||||
...chapters[chapterIndex],
|
||||
isAvailable: isAvailable
|
||||
};
|
||||
|
||||
// Créer un nouveau tableau pour garantir la réactivité
|
||||
const updatedChapters = [...chapters];
|
||||
updatedChapters[chapterIndex] = updatedChapter;
|
||||
|
||||
// Mise à jour reactive du store
|
||||
this.mangaChapters[mangaId] = {
|
||||
...chaptersObj,
|
||||
items: updatedChapters
|
||||
};
|
||||
|
||||
console.log('Chapitre mis à jour avec succès');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// --- Search Actions ---
|
||||
async searchMangaDex(query) {
|
||||
if (this.loadingSearch) return;
|
||||
@@ -130,16 +189,13 @@ export const useMangaStore = defineStore('manga', {
|
||||
}
|
||||
},
|
||||
|
||||
// --- Chapter Actions ---
|
||||
// --- Scrape Chapter Action ---
|
||||
async searchChapter(chapterId) {
|
||||
try {
|
||||
await mangaRepository.searchChapter(chapterId);
|
||||
// Rafraîchir la collection après la recherche
|
||||
await this.refreshCollectionInBackground();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la recherche du chapitre:', error);
|
||||
return false;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user