From af74657f1afc0ec6751573f73934b80ec3e78690 Mon Sep 17 00:00:00 2001 From: Cooper Ransom Date: Thu, 4 Apr 2024 10:06:09 -0400 Subject: [PATCH] Fix scrolling bug --- src/pages/Discover.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pages/Discover.tsx b/src/pages/Discover.tsx index ba0334f8..ae1c8422 100644 --- a/src/pages/Discover.tsx +++ b/src/pages/Discover.tsx @@ -197,14 +197,22 @@ export function Discover() { } }, [movieWidth]); // Added movieWidth to the dependency array + let isScrolling = false; + function handleWheel(e: React.WheelEvent, categorySlug: string) { + if (isScrolling) { + return; + } + + isScrolling = true; + const carousel = carouselRefs.current[categorySlug]; if (carousel) { const movieElements = carousel.getElementsByTagName("a"); if (movieElements.length > 0) { const posterWidth = movieElements[0].offsetWidth; const visibleMovies = Math.floor(carousel.offsetWidth / posterWidth); - const scrollAmount = posterWidth * visibleMovies * 0.625; + const scrollAmount = posterWidth * visibleMovies * 0.6; if (e.deltaY < 5) { carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" }); } else { @@ -212,6 +220,10 @@ export function Discover() { } } } + + setTimeout(() => { + isScrolling = false; + }, 345); // Disable scrolling every 3 milliseconds after interaction (only for mouse wheel doe) } const [isHovered, setIsHovered] = useState(false);