diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f9f6a79..3fb40e91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,7 +32,7 @@ dependencies: version: 1.0.3 '@movie-web/providers': specifier: github:sussy-code/providers - version: github.com/sussy-code/providers/9b6eb8417c7e2cd2c4265b7102ac5ed299022a42 + version: github.com/sussy-code/providers/b04c921b5533e6f53a58c3a0406d90ad2f076c05 '@noble/hashes': specifier: ^1.4.0 version: 1.4.0 @@ -7430,10 +7430,11 @@ packages: use-sync-external-store: 1.2.0(react@18.3.1) dev: false - github.com/sussy-code/providers/9b6eb8417c7e2cd2c4265b7102ac5ed299022a42: - resolution: {tarball: https://codeload.github.com/sussy-code/providers/tar.gz/9b6eb8417c7e2cd2c4265b7102ac5ed299022a42} + github.com/sussy-code/providers/b04c921b5533e6f53a58c3a0406d90ad2f076c05: + resolution: {tarball: https://codeload.github.com/sussy-code/providers/tar.gz/b04c921b5533e6f53a58c3a0406d90ad2f076c05} name: '@movie-web/providers' version: 2.3.0 + prepare: true requiresBuild: true dependencies: cheerio: 1.0.0-rc.12 diff --git a/src/pages/Discover.tsx b/src/pages/Discover.tsx index e578a626..c6452438 100644 --- a/src/pages/Discover.tsx +++ b/src/pages/Discover.tsx @@ -226,7 +226,6 @@ export function Discover() { genres.forEach((genre) => fetchMoviesForGenre(genre.id)); }, [genres]); - // Update the scrollCarousel function to use the new ref map function scrollCarousel(categorySlug: string, direction: string) { const carousel = carouselRefs.current[categorySlug]; if (carousel) { @@ -237,22 +236,7 @@ export function Discover() { const scrollAmount = movieWidth * visibleMovies * 0.69; // Silly number :3 if (direction === "left") { - if (carousel.scrollLeft <= 5) { - carousel.scrollBy({ - left: carousel.scrollWidth, - behavior: "smooth", - }); // Scroll to the end - } else { - carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" }); - } - } else if ( - carousel.scrollLeft + carousel.offsetWidth + 5 >= - carousel.scrollWidth - ) { - carousel.scrollBy({ - left: -carousel.scrollWidth, - behavior: "smooth", - }); // Scroll to the beginning + carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" }); } else { carousel.scrollBy({ left: scrollAmount, behavior: "smooth" }); } @@ -284,42 +268,39 @@ export function Discover() { } }, [movieWidth]); + const browser = !!window.chrome; // detect chromium browser let isScrolling = false; + function handleWheel(e: React.WheelEvent, categorySlug: string) { if (isScrolling) { return; } isScrolling = true; - const carousel = carouselRefs.current[categorySlug]; - if (carousel && !e.deltaX) { + 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.62; if (e.deltaY < 5) { - carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" }); + scrollCarousel(categorySlug, "left"); } else { - carousel.scrollBy({ left: scrollAmount, behavior: "smooth" }); + scrollCarousel(categorySlug, "right"); } } } - setTimeout(() => { + if (browser) { + setTimeout(() => { + isScrolling = false; + }, 345); // disable scrolling after 345 milliseconds for chromium-based browsers + } else { + // immediately reset isScrolling for non-chromium browsers isScrolling = false; - }, 345); // Disable scrolling every 3 milliseconds after interaction (only for mouse wheel doe) + } } const [isHovered, setIsHovered] = useState(false); - useEffect(() => { - if (!isHovered) { - document.body.style.overflow = "auto"; - } - }, [isHovered]); - const handleMouseEnter = () => { document.body.style.overflow = "hidden"; setIsHovered(true); @@ -329,6 +310,12 @@ export function Discover() { setIsHovered(false); }; + useEffect(() => { + if (!isHovered) { + document.body.style.overflow = "auto"; + } + }, [isHovered]); + function renderMovies(medias: Media[], category: string, isTVShow = false) { const categorySlug = `${category.toLowerCase().replace(/ /g, "-")}${Math.random()}`; // Convert the category to a slug const displayCategory =