diff --git a/client/src/components/netflix-grid.tsx b/client/src/components/netflix-grid.tsx
index bda5228..639ad0c 100644
--- a/client/src/components/netflix-grid.tsx
+++ b/client/src/components/netflix-grid.tsx
@@ -141,14 +141,12 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
const videosToShow = 5; // Show 5 videos at a time
const scroll = (direction: 'left' | 'right') => {
- const totalVideos = category.videos.length;
-
if (direction === 'right') {
- // Move one video forward (shift left to show next video)
- setCurrentIndex(prev => (prev + 1) % totalVideos);
+ // Always move forward, let infinite loop handle the reset
+ setCurrentIndex(prev => prev + 1);
} else {
- // Move one video backward (shift right to show previous video)
- setCurrentIndex(prev => prev === 0 ? totalVideos - 1 : prev - 1);
+ // Always move backward, let infinite loop handle the reset
+ setCurrentIndex(prev => prev - 1);
}
};
@@ -157,14 +155,22 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
scroll(direction);
};
- // Handle infinite scroll reset
+ // Initialize in middle section for true infinite scroll
+ useEffect(() => {
+ if (category.videos.length > 0) {
+ setCurrentIndex(category.videos.length); // Start in middle section
+ }
+ }, [category.videos.length]);
+
+ // Handle seamless infinite scroll
useEffect(() => {
const totalVideos = category.videos.length;
- if (currentIndex >= totalVideos) {
- // Reset to beginning for infinite loop
- setTimeout(() => {
- setCurrentIndex(0);
- }, 500); // After animation completes
+ if (currentIndex >= totalVideos * 2) {
+ // Jump from end of 2nd section to start of 1st section
+ setCurrentIndex(totalVideos);
+ } else if (currentIndex < 0) {
+ // Jump from before 1st section to start of 2nd section
+ setCurrentIndex(totalVideos - 1);
}
}, [currentIndex, category.videos.length]);
@@ -266,35 +272,39 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {