Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrolling on discover page #24

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions src/pages/Discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
}, [movieWidth]);

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

Check warning on line 288 in src/pages/Discover.tsx

View workflow job for this annotation

GitHub Actions / Run Linters

'handleWheel' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 288 in src/pages/Discover.tsx

View workflow job for this annotation

GitHub Actions / Build project

'handleWheel' is defined but never used. Allowed unused vars must match /^_/u
if (isScrolling) {
return;
}
Expand All @@ -293,7 +293,7 @@
isScrolling = true;

const carousel = carouselRefs.current[categorySlug];
if (carousel) {
if (carousel && !e.deltaX) {
const movieElements = carousel.getElementsByTagName("a");
if (movieElements.length > 0) {
const posterWidth = movieElements[0].offsetWidth;
Expand All @@ -312,23 +312,6 @@
}, 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);
};

const handleMouseLeave = () => {
setIsHovered(false);
};

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 Expand Up @@ -357,9 +340,6 @@
ref={(el) => {
carouselRefs.current[categorySlug] = el;
}}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onWheel={(e) => handleWheel(e, categorySlug)}
>
{medias
.filter((media, index, self) => {
Expand Down
Loading