diff --git a/client/src/components/netflix-grid.tsx b/client/src/components/netflix-grid.tsx index d54f443..25e0c7a 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 to next video in circle: 1→2→3...→10→1 - setCurrentIndex(prev => (prev + 1) % totalVideos); + // Move one video to the right - smooth sliding like geese + setCurrentIndex(prev => prev + 1); } else { - // Move to previous video in circle: 1→10→9...→2→1 - setCurrentIndex(prev => prev === 0 ? totalVideos - 1 : prev - 1); + // Move one video to the left - smooth sliding like geese + setCurrentIndex(prev => prev - 1); } }; @@ -164,11 +162,25 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) { }, 800); // Auto scroll every 800ms }; - // Always start with video 1 at first position + // Initialize in middle section for smooth infinite scroll useEffect(() => { - setCurrentIndex(0); + if (category.videos.length > 0) { + setCurrentIndex(category.videos.length); // Start in middle section for smooth wrapping + } }, [category.videos.length]); + // Handle seamless infinite scroll wrapping + useEffect(() => { + const totalVideos = category.videos.length; + if (currentIndex >= totalVideos * 2) { + // Seamlessly jump from end to middle + setCurrentIndex(totalVideos); + } else if (currentIndex < 0) { + // Seamlessly jump from beginning to middle + setCurrentIndex(totalVideos - 1); + } + }, [currentIndex, category.videos.length]); + // Always show both buttons useEffect(() => { setShowLeftButton(true); @@ -271,33 +283,41 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) { - {/* Simple carousel that shows current videos */} -
- {Array.from({ length: videosToShow }, (_, index) => { - const videoIndex = (currentIndex + index) % category.videos.length; - const video = category.videos[videoIndex]; - return ( -
- {/* Top 10 Number overlay for first category */} - {category.title.includes("Top 10") && ( -
- {videoIndex + 1} -
- )} - -
- ); - })} + {/* Smooth sliding carousel - videos move like geese one by one */} +
+
+ {/* Create infinite loop by tripling the videos */} + {[...category.videos, ...category.videos, ...category.videos].map((video, index) => { + const actualIndex = index % category.videos.length; + return ( +
+ {/* Top 10 Number overlay for first category */} + {category.title.includes("Top 10") && ( +
+ {actualIndex + 1} +
+ )} + +
+ ); + })} +