diff --git a/client/src/components/netflix-grid.tsx b/client/src/components/netflix-grid.tsx
index 2472570..27c2ad3 100644
--- a/client/src/components/netflix-grid.tsx
+++ b/client/src/components/netflix-grid.tsx
@@ -137,20 +137,16 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
const [showLeftButton, setShowLeftButton] = useState(false);
const [showRightButton, setShowRightButton] = useState(true);
- // Create infinite carousel by duplicating videos
- const infiniteVideos = [...category.videos, ...category.videos, ...category.videos];
+ const [currentIndex, setCurrentIndex] = useState(0);
+ const videosToShow = 5; // Show 5 videos at a time
const scroll = (direction: 'left' | 'right') => {
- if (!scrollRef.current) return;
-
- const container = scrollRef.current;
- const videoWidth = 224; // approx width of one video card + spacing
- const scrollAmount = videoWidth * 2; // Show 2 videos at a time
+ const totalVideos = category.videos.length;
if (direction === 'left') {
- container.scrollBy({ left: -scrollAmount, behavior: 'smooth' });
+ setCurrentIndex(prev => prev === 0 ? totalVideos - 1 : prev - 1);
} else {
- container.scrollBy({ left: scrollAmount, behavior: 'smooth' });
+ setCurrentIndex(prev => prev === totalVideos - 1 ? 0 : prev + 1);
}
};
@@ -159,38 +155,26 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
scroll(direction);
};
- const checkScrollPosition = () => {
- if (!scrollRef.current) return;
+ // Get visible videos based on current index
+ const getVisibleVideos = () => {
+ const totalVideos = category.videos.length;
+ const visible = [];
- const container = scrollRef.current;
- const currentScroll = container.scrollLeft;
- const maxScroll = container.scrollWidth - container.clientWidth;
- const sectionWidth = (container.scrollWidth / 3); // One third (original videos)
-
- // Reset to middle section when approaching edges for infinite effect
- if (currentScroll <= 100) {
- // Jump to end of first section (start of second section)
- container.scrollLeft = sectionWidth + currentScroll;
- } else if (currentScroll >= maxScroll - 100) {
- // Jump to start of second section
- container.scrollLeft = sectionWidth + (currentScroll - 2 * sectionWidth);
+ for (let i = 0; i < videosToShow; i++) {
+ const index = (currentIndex + i) % totalVideos;
+ visible.push({
+ ...category.videos[index],
+ displayIndex: i
+ });
}
-
- // Always show both buttons
- setShowLeftButton(true);
- setShowRightButton(true);
+ return visible;
};
- // Initialize position to middle section on mount
+ // Always show both buttons
useEffect(() => {
- if (scrollRef.current && category.videos.length > 0) {
- const container = scrollRef.current;
- const sectionWidth = container.scrollWidth / 3;
- container.scrollLeft = sectionWidth; // Start in middle section
- setShowLeftButton(true);
- setShowRightButton(true);
- }
- }, [category.videos]);
+ setShowLeftButton(true);
+ setShowRightButton(true);
+ }, []);
const stopAutoScroll = () => {
if (scrollIntervalRef.current) {
@@ -284,37 +268,30 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {