Improve video browsing experience with continuous scrolling

Refactor Netflix grid component to use state for current index and implement circular auto-scrolling with setInterval, replacing the previous animation approach.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 2eb1084e-b728-4449-9231-f1665924c8d5
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2eb1084e-b728-4449-9231-f1665924c8d5/QCN70f2
This commit is contained in:
sebastjanartic 2025-08-29 15:10:16 +00:00
parent b6243d5c19
commit cd1a846b14
3 changed files with 46 additions and 75 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 KiB

View File

@ -133,59 +133,39 @@ interface CategoryRowProps {
function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
const scrollRef = useRef<HTMLDivElement>(null);
const scrollIntervalRef = useRef<number | null>(null);
const scrollIntervalRef = useRef<NodeJS.Timeout | null>(null);
const [showLeftButton, setShowLeftButton] = useState(false);
const [showRightButton, setShowRightButton] = useState(true);
const [translateX, setTranslateX] = useState(0);
const [isAnimating, setIsAnimating] = useState(false);
const [currentIndex, setCurrentIndex] = useState(0);
const videosToShow = 5; // Show 5 videos at a time
const videoWidth = 120; // Width including spacing
const scroll = (direction: 'left' | 'right') => {
const step = direction === 'right' ? -videoWidth : videoWidth;
setTranslateX(prev => prev + step);
const totalVideos = category.videos.length;
if (direction === 'right') {
// Move to next video in circular fashion: 1→2→3→...→10→1→2→...
setCurrentIndex(prev => (prev + 1) % totalVideos);
} else {
// Move to previous video in circular fashion: 1→10→9→...→2→1→10→...
setCurrentIndex(prev => prev === 0 ? totalVideos - 1 : prev - 1);
}
};
const startAutoScroll = (direction: 'left' | 'right') => {
// Clear any existing animation
// Clear any existing interval
if (scrollIntervalRef.current) {
cancelAnimationFrame(scrollIntervalRef.current);
clearInterval(scrollIntervalRef.current);
}
setIsAnimating(true);
// Continuous smooth animation - no jumping
const speed = direction === 'right' ? -1 : 1; // Pixels per frame
const animate = () => {
setTranslateX(prev => {
const newX = prev + speed;
const totalWidth = category.videos.length * videoWidth;
// Infinite loop - reset seamlessly
if (direction === 'right' && newX <= -totalWidth) {
return 0; // Reset to start for infinite loop
} else if (direction === 'left' && newX >= 0) {
return -totalWidth + videoWidth; // Reset for reverse
}
return newX;
});
if (isAnimating) {
scrollIntervalRef.current = requestAnimationFrame(animate);
}
};
animate();
// Start continuous circular scrolling
scrollIntervalRef.current = setInterval(() => {
scroll(direction);
}, 600); // Auto scroll every 600ms
};
// Always start with video 1 visible at first position
useEffect(() => {
if (category.videos.length > 0) {
setTranslateX(0); // Start with video 1 at first position
}
setCurrentIndex(0); // Start with video 1 at first position
}, [category.videos.length]);
// Always show both buttons
@ -195,9 +175,8 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
}, []);
const stopAutoScroll = () => {
setIsAnimating(false);
if (scrollIntervalRef.current) {
cancelAnimationFrame(scrollIntervalRef.current);
clearInterval(scrollIntervalRef.current);
scrollIntervalRef.current = null;
}
};
@ -291,42 +270,34 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
<ChevronRight className="w-5 h-5 text-white" />
</button>
{/* Continuously flowing carousel */}
<div className="overflow-hidden">
<div
className="flex space-x-2 md:space-x-3 pb-4 px-4 md:px-0"
style={{
transform: `translateX(${translateX}px)`,
willChange: 'transform',
transition: isAnimating ? 'none' : 'transform 0.3s ease'
}}
>
{/* Create infinite loop by tripling the videos */}
{[...category.videos, ...category.videos, ...category.videos].map((video, index) => {
const actualIndex = index % category.videos.length;
return (
<div key={`${video.id}-${Math.floor(index / category.videos.length)}-${actualIndex}`} className="flex-shrink-0 w-28 md:w-52 relative group">
{/* Top 10 Number overlay for first category */}
{category.title.includes("Top 10") && (
<div className="absolute top-1 left-1 z-30 text-white font-black text-3xl md:text-5xl drop-shadow-2xl pointer-events-none"
style={{
textShadow: '4px 4px 8px rgba(0,0,0,0.8), -2px -2px 4px rgba(0,0,0,0.6)',
WebkitTextStroke: '2px rgba(0,0,0,0.8)',
transform: 'none',
transition: 'none'
}}>
{actualIndex + 1}
</div>
)}
<VideoCard
video={video}
onClick={onVideoClick}
className="w-full hover:scale-105 hover:z-10 transition-all duration-300 group-hover:shadow-xl rounded-md overflow-hidden"
/>
</div>
);
})}
</div>
{/* Circular carousel - videos rotate in circle */}
<div className="flex space-x-2 md:space-x-3 pb-4 px-4 md:px-0">
{/* Show 5 videos in circular fashion */}
{Array.from({ length: videosToShow }, (_, index) => {
const videoIndex = (currentIndex + index) % category.videos.length;
const video = category.videos[videoIndex];
return (
<div key={`${videoIndex}-${index}`} className="flex-shrink-0 w-28 md:w-52 relative group transition-all duration-300">
{/* Top 10 Number overlay for first category */}
{category.title.includes("Top 10") && (
<div className="absolute top-1 left-1 z-30 text-white font-black text-3xl md:text-5xl drop-shadow-2xl pointer-events-none"
style={{
textShadow: '4px 4px 8px rgba(0,0,0,0.8), -2px -2px 4px rgba(0,0,0,0.6)',
WebkitTextStroke: '2px rgba(0,0,0,0.8)',
transform: 'none',
transition: 'none'
}}>
{videoIndex + 1}
</div>
)}
<VideoCard
video={video}
onClick={onVideoClick}
className="w-full hover:scale-105 hover:z-10 transition-all duration-300 group-hover:shadow-xl rounded-md overflow-hidden"
/>
</div>
);
})}
</div>
</div>
</div>