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