Skip to content

Commit

Permalink
Fix scrolling again
Browse files Browse the repository at this point in the history
  • Loading branch information
leodenham committed May 11, 2024
1 parent a52d63e commit b67fc99
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/pages/Discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,49 @@ export function Discover() {
}
}, [movieWidth]);

let isScrolling = false;
function handleWheel(e: React.WheelEvent, categorySlug: string) {
if (isScrolling) {
return;
}

isScrolling = true;

const carousel = carouselRefs.current[categorySlug];
if (carousel && !e.deltaX) {
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.62;
if (e.deltaY < 5) {
carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" });
} else {
carousel.scrollBy({ left: scrollAmount, behavior: "smooth" });
}
}
}

setTimeout(() => {
isScrolling = false;
}, 345); // Disable scrolling every 3 milliseconds after interaction (only for mouse wheel doe)
}

const handleMouseEnter = () => {
document.body.style.overflow = "hidden";
};

const handleMouseLeave = () => {
document.body.style.overflow = "auto";
};

useEffect(() => {
window.addEventListener("mouseleave", handleMouseLeave);
return () => {
window.removeEventListener("mouseleave", handleMouseLeave);
};
}, []);

function renderMovies(medias: Media[], category: string, isTVShow = false) {
const categorySlug = `${category.toLowerCase().replace(/ /g, "-")}${Math.random()}`; // Convert the category to a slug
const displayCategory =
Expand Down

0 comments on commit b67fc99

Please sign in to comment.