diff --git a/src/components/reader/BookReader.tsx b/src/components/reader/BookReader.tsx index 4467d7b..47cfe45 100644 --- a/src/components/reader/BookReader.tsx +++ b/src/components/reader/BookReader.tsx @@ -351,37 +351,31 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) { setLoadedThumbnails((prev) => ({ ...prev, [pageNumber]: true })); }; - // Fonction pour scroller jusqu'à la miniature active + // Effet pour scroller jusqu'à la miniature active const scrollToActiveThumbnail = useCallback(() => { - const container = document.getElementById("thumbnails-container"); - const activeThumbnail = document.getElementById(`thumbnail-${currentPage}`); - if (container && activeThumbnail) { - const containerWidth = container.clientWidth; - const thumbnailLeft = activeThumbnail.offsetLeft; - const thumbnailWidth = activeThumbnail.clientWidth; - - // Centrer la miniature dans le conteneur - container.scrollLeft = thumbnailLeft - containerWidth / 2 + thumbnailWidth / 2; + const thumbnail = document.getElementById(`thumbnail-${currentPage}`); + if (thumbnail) { + thumbnail.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "center", + }); } }, [currentPage]); - // Effet pour scroller jusqu'à la miniature active au chargement et au changement de page + // Effet pour centrer la miniature active quand les contrôles deviennent visibles useEffect(() => { - if (showNavigation) { + if (showControls) { scrollToActiveThumbnail(); } - }, [currentPage, showNavigation, scrollToActiveThumbnail]); + }, [showControls, scrollToActiveThumbnail]); - // Effet pour scroller jusqu'à la miniature active quand la navigation devient visible + // Effet pour centrer la miniature active au changement de page useEffect(() => { - if (showNavigation) { - // Petit délai pour laisser le temps à la barre de s'afficher - const timer = setTimeout(() => { - scrollToActiveThumbnail(); - }, 100); - return () => clearTimeout(timer); + if (showControls) { + scrollToActiveThumbnail(); } - }, [showNavigation, scrollToActiveThumbnail]); + }, [currentPage, showControls, scrollToActiveThumbnail]); // Fonction pour calculer les miniatures à afficher autour de la page courante const updateVisibleThumbnails = useCallback(() => { @@ -504,20 +498,6 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) { )} - {/* Bouton précédent */} {currentPage > 1 && ( @@ -630,31 +610,17 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) {
- {showNavigation && ( + {showControls && ( <> -
- -
-
+ {/* Ajouter un élément vide au début pour le centrage */} +
{pages.map((_, index) => { const pageNumber = index + 1; const isVisible = visibleThumbnails.includes(pageNumber); @@ -674,10 +640,10 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) { setImageError(false); syncReadProgress(pageNumber); }} - className={`relative h-40 w-28 flex-shrink-0 rounded-md overflow-hidden transition-all cursor-pointer ${ + className={`relative h-56 w-40 flex-shrink-0 rounded-md overflow-hidden transition-all cursor-pointer snap-center ${ currentPage === pageNumber ? "ring-2 ring-primary scale-110 z-10" - : "opacity-60 hover:opacity-100 hover:scale-105" + : "opacity-80 hover:opacity-100 hover:scale-105" }`} > {isVisible && ( @@ -704,21 +670,8 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) { ); })} -
- -
- + {/* Ajouter un élément vide à la fin pour le centrage */} +
{/* Indicateur de page */}