feat: no nav on click if too small window
This commit is contained in:
@@ -2,7 +2,7 @@ import { NavigationBarProps } from "../types";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Thumbnail } from "./Thumbnail";
|
import { Thumbnail } from "./Thumbnail";
|
||||||
import { useThumbnails } from "../hooks/useThumbnails";
|
import { useThumbnails } from "../hooks/useThumbnails";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
export const NavigationBar = ({
|
export const NavigationBar = ({
|
||||||
currentPage,
|
currentPage,
|
||||||
@@ -11,6 +11,7 @@ export const NavigationBar = ({
|
|||||||
showControls,
|
showControls,
|
||||||
book,
|
book,
|
||||||
}: NavigationBarProps) => {
|
}: NavigationBarProps) => {
|
||||||
|
const [isTooSmall, setIsTooSmall] = useState(false);
|
||||||
const { loadedThumbnails, handleThumbnailLoad, getThumbnailUrl, visibleThumbnails } =
|
const { loadedThumbnails, handleThumbnailLoad, getThumbnailUrl, visibleThumbnails } =
|
||||||
useThumbnails({
|
useThumbnails({
|
||||||
book,
|
book,
|
||||||
@@ -19,9 +20,20 @@ export const NavigationBar = ({
|
|||||||
|
|
||||||
const thumbnailsContainerRef = useRef<HTMLDivElement>(null);
|
const thumbnailsContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// Vérification de la hauteur de la fenêtre
|
||||||
|
useEffect(() => {
|
||||||
|
const checkHeight = () => {
|
||||||
|
setIsTooSmall(window.innerHeight < 580);
|
||||||
|
};
|
||||||
|
|
||||||
|
checkHeight();
|
||||||
|
window.addEventListener("resize", checkHeight);
|
||||||
|
return () => window.removeEventListener("resize", checkHeight);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Scroll à l'ouverture des contrôles et au changement de page
|
// Scroll à l'ouverture des contrôles et au changement de page
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showControls) {
|
if (showControls && !isTooSmall) {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const thumbnail = document.getElementById(`thumbnail-${currentPage}`);
|
const thumbnail = document.getElementById(`thumbnail-${currentPage}`);
|
||||||
if (thumbnail) {
|
if (thumbnail) {
|
||||||
@@ -33,7 +45,11 @@ export const NavigationBar = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [showControls, currentPage]);
|
}, [showControls, currentPage, isTooSmall]);
|
||||||
|
|
||||||
|
if (isTooSmall) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user