From d123166dcbcce46a92b7663a1e282ebe90c8986f Mon Sep 17 00:00:00 2001 From: "ext.jeremy.guillot@maxicoffee.domains" Date: Wed, 26 Mar 2025 23:08:12 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20simplification=20du=20store=20de=20?= =?UTF-8?q?lecteur=20en=20supprimant=20les=20logs=20de=20d=C3=A9bogage=20e?= =?UTF-8?q?t=20en=20optimisant=20les=20getters=20pour=20une=20meilleure=20?= =?UTF-8?q?lisibilit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reader/application/store/readerStore.js | 68 +------------------ .../presentation/components/ChapterReader.vue | 46 +------------ 2 files changed, 3 insertions(+), 111 deletions(-) diff --git a/assets/vue/app/domain/reader/application/store/readerStore.js b/assets/vue/app/domain/reader/application/store/readerStore.js index 940171a..e3d2360 100644 --- a/assets/vue/app/domain/reader/application/store/readerStore.js +++ b/assets/vue/app/domain/reader/application/store/readerStore.js @@ -12,70 +12,39 @@ export const useReaderStore = defineStore('reader', { isLoading: false, error: null, pages: [], - totalPages: 0, - _debug: { - lastUpdate: Date.now(), - lastAction: null - } + totalPages: 0 }), getters: { isFirstPage: state => state.currentPage === 0, isLastPage: state => state.currentPage === state.totalPages - 1, - currentPageData: state => { - const data = state.pages[state.currentPage]; - console.log('Getting currentPageData:', { - currentPage: state.currentPage, - hasData: !!data, - totalPages: state.totalPages, - pagesLength: state.pages.length, - lastUpdate: state._debug.lastUpdate, - lastAction: state._debug.lastAction - }); - return data; - } + currentPageData: state => state.pages[state.currentPage] }, actions: { async loadChapter(chapterId) { - console.log('Loading chapter:', chapterId); this.isLoading = true; this.error = null; - this._debug.lastAction = 'loadChapter'; try { const repository = new ApiChapterRepository(); // Charger les informations du chapitre - console.log('Fetching chapter info...'); const chapterData = await repository.getChapter(chapterId); - console.log('Chapter data received:', chapterData); this.currentChapter = Chapter.create(chapterData); // Charger la liste des pages - console.log('Fetching pages info...'); const pagesData = await repository.getChapterPages(chapterId); - console.log('Pages data received:', pagesData); // Initialiser le tableau avec des placeholders this.pages = new Array(pagesData.totalItems).fill(null); this.totalPages = pagesData.totalItems; - this._debug.lastUpdate = Date.now(); - - console.log('Pages array initialized:', { - length: this.pages.length, - totalPages: this.totalPages - }); // Charger la première page if (this.totalPages > 0) { - console.log('Loading first page...'); this.currentPage = 0; await this.loadCurrentPageData(); - } else { - console.warn('No pages available for this chapter'); } } catch (error) { - console.error('Error loading chapter:', error); this.error = error.message; } finally { this.isLoading = false; @@ -84,38 +53,24 @@ export const useReaderStore = defineStore('reader', { async loadCurrentPageData() { if (!this.currentChapter) { - console.error('No current chapter loaded'); return; } if (this.currentPage < 0 || this.currentPage >= this.totalPages) { - console.error('Invalid page index:', this.currentPage); return; } const pageNumber = this.currentPage + 1; // Convertir en 1-based pour l'API - console.log('Loading page data:', { - pageNumber, - chapterId: this.currentChapter.id - }); if (this.pages[this.currentPage]?.base64Content) { - console.log('Page already loaded, skipping fetch'); return; } this.isLoading = true; this.error = null; - this._debug.lastAction = 'loadCurrentPageData'; try { const repository = new ApiChapterRepository(); - console.log('Fetching page from API...'); const pageData = await repository.getChapterPage(this.currentChapter.id, pageNumber); - console.log('Page data received:', { - hasContent: !!pageData?.base64Content, - mimeType: pageData?.mimeType, - pageNumber: pageData?.pageNumber - }); // Vérifier que les données sont valides if (!pageData || !pageData.base64Content) { @@ -132,14 +87,7 @@ export const useReaderStore = defineStore('reader', { dimensions: pageData.dimensions }; this.pages = newPages; - this._debug.lastUpdate = Date.now(); - - console.log('Page data updated in store:', { - pageIndex: this.currentPage, - hasContent: !!this.pages[this.currentPage]?.base64Content - }); } catch (error) { - console.error('Error loading page:', error); this.error = error.message; } finally { this.isLoading = false; @@ -148,40 +96,28 @@ export const useReaderStore = defineStore('reader', { async nextPage() { if (!this.isLastPage) { - console.log('Moving to next page'); this.currentPage++; - this._debug.lastAction = 'nextPage'; - this._debug.lastUpdate = Date.now(); await this.loadCurrentPageData(); } }, async previousPage() { if (!this.isFirstPage) { - console.log('Moving to previous page'); this.currentPage--; - this._debug.lastAction = 'previousPage'; - this._debug.lastUpdate = Date.now(); await this.loadCurrentPageData(); } }, setReadingMode(mode) { this.readingMode = mode; - this._debug.lastAction = 'setReadingMode'; - this._debug.lastUpdate = Date.now(); }, setReadingDirection(direction) { this.readingDirection = direction; - this._debug.lastAction = 'setReadingDirection'; - this._debug.lastUpdate = Date.now(); }, setZoom(level) { this.zoom = level; - this._debug.lastAction = 'setZoom'; - this._debug.lastUpdate = Date.now(); } } }); diff --git a/assets/vue/app/domain/reader/presentation/components/ChapterReader.vue b/assets/vue/app/domain/reader/presentation/components/ChapterReader.vue index c808093..84d5ed3 100644 --- a/assets/vue/app/domain/reader/presentation/components/ChapterReader.vue +++ b/assets/vue/app/domain/reader/presentation/components/ChapterReader.vue @@ -22,13 +22,7 @@
Aucune donnée d'image disponible
Contenu de l'image manquant
- +
@@ -44,26 +38,6 @@
- -
- currentPage: {{ store.currentPage }}
- totalPages: {{ store.totalPages }}
- hasCurrentPageData: {{ !!store.currentPageData }}
- hasBase64Content: {{ !!store.currentPageData?.base64Content }}
- mimeType: {{ store.currentPageData?.mimeType }}
- lastAction: {{ store._debug.lastAction }}
- lastUpdate: {{ new Date(store._debug.lastUpdate).toLocaleTimeString() }} -
@@ -83,29 +57,12 @@ const store = useReaderStore(); const imageSource = computed(() => { - console.log('Computing imageSource:', { - hasCurrentPageData: !!store.currentPageData, - mimeType: store.currentPageData?.mimeType, - hasContent: !!store.currentPageData?.base64Content - }); - if (!store.currentPageData?.base64Content || !store.currentPageData?.mimeType) { - console.error("Données d'image invalides:", store.currentPageData); return ''; } return `data:${store.currentPageData.mimeType};base64,${store.currentPageData.base64Content}`; }); - const handleImageError = e => { - console.error("Erreur de chargement de l'image:", e); - console.log("Source de l'image:", imageSource.value); - console.log('Données de la page:', store.currentPageData); - }; - - const handleImageLoad = () => { - console.log('Image chargée avec succès'); - }; - const toggleReadingMode = () => { store.setReadingMode(store.readingMode === 'single' ? 'infinite' : 'single'); }; @@ -134,7 +91,6 @@ () => props.chapterId, newId => { if (newId) { - console.log('ChapterId changed, loading new chapter:', newId); store.loadChapter(newId); } },