Implement a smooth scrolling carousel for video categories
Introduces a new `SimpleCarousel` component to replace `CategoryRow` for displaying videos within categories, enabling smooth horizontal scrolling with auto-scroll and navigation buttons. 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/yexZbDm
This commit is contained in:
parent
95cc839838
commit
855d7e2448
BIN
attached_assets/image_1756487706679.png
Normal file
BIN
attached_assets/image_1756487706679.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 372 KiB |
@ -4,6 +4,7 @@ import VideoCard from "./video-card";
|
||||
import BunnyVideoModal from "./bunny-video-modal";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import SimpleCarousel from "./simple-carousel";
|
||||
|
||||
interface VideoCategory {
|
||||
title: string;
|
||||
@ -107,7 +108,7 @@ export default function NetflixGrid({ videos, isLoading }: NetflixGridProps) {
|
||||
<>
|
||||
<div className="space-y-12 relative z-10">
|
||||
{categories.map((category, categoryIndex) => (
|
||||
<CategoryRow
|
||||
<SimpleCarousel
|
||||
key={categoryIndex}
|
||||
category={category}
|
||||
onVideoClick={handleVideoClick}
|
||||
@ -131,7 +132,7 @@ interface CategoryRowProps {
|
||||
onVideoClick: (video: Video) => void;
|
||||
}
|
||||
|
||||
function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
|
||||
function CategoryRowOLD_BROKEN({ category, onVideoClick }: CategoryRowProps) {
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const scrollIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
123
client/src/components/simple-carousel.tsx
Normal file
123
client/src/components/simple-carousel.tsx
Normal file
@ -0,0 +1,123 @@
|
||||
import { useState, useRef } from "react";
|
||||
import { type Video } from "@shared/schema";
|
||||
import VideoCard from "./video-card";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
|
||||
interface SimpleCarouselProps {
|
||||
category: {
|
||||
title: string;
|
||||
videos: Video[];
|
||||
};
|
||||
onVideoClick: (video: Video) => void;
|
||||
}
|
||||
|
||||
export default function SimpleCarousel({ category, onVideoClick }: SimpleCarouselProps) {
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
const scrollIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const [isScrolling, setIsScrolling] = useState(false);
|
||||
|
||||
const scroll = (direction: 'left' | 'right') => {
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const scrollAmount = direction === 'right' ? 300 : -300;
|
||||
scrollContainerRef.current.scrollBy({
|
||||
left: scrollAmount,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
};
|
||||
|
||||
const startAutoScroll = (direction: 'left' | 'right') => {
|
||||
if (scrollIntervalRef.current) {
|
||||
clearInterval(scrollIntervalRef.current);
|
||||
}
|
||||
|
||||
setIsScrolling(true);
|
||||
|
||||
scrollIntervalRef.current = setInterval(() => {
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const speed = 3;
|
||||
const scrollAmount = direction === 'right' ? speed : -speed;
|
||||
scrollContainerRef.current.scrollBy({
|
||||
left: scrollAmount,
|
||||
behavior: 'auto'
|
||||
});
|
||||
}, 16);
|
||||
};
|
||||
|
||||
const stopAutoScroll = () => {
|
||||
if (scrollIntervalRef.current) {
|
||||
clearInterval(scrollIntervalRef.current);
|
||||
scrollIntervalRef.current = null;
|
||||
}
|
||||
setIsScrolling(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative group mb-8">
|
||||
<h2 className="text-2xl font-bold text-bunny-light mb-6 px-4">
|
||||
{category.title}
|
||||
</h2>
|
||||
|
||||
<div className="relative">
|
||||
{/* Left scroll button */}
|
||||
<button
|
||||
onClick={() => scroll('left')}
|
||||
onMouseEnter={() => startAutoScroll('left')}
|
||||
onMouseLeave={stopAutoScroll}
|
||||
className="absolute left-2 top-[45%] -translate-y-1/2 w-12 h-12 z-30 bg-black/80 hover:bg-black/95 rounded-full flex items-center justify-center transition-all duration-300 cursor-pointer border border-white/30 shadow-lg opacity-80 hover:!opacity-100"
|
||||
>
|
||||
<ChevronLeft className="w-6 h-6 text-white" />
|
||||
</button>
|
||||
|
||||
{/* Right scroll button */}
|
||||
<button
|
||||
onClick={() => scroll('right')}
|
||||
onMouseEnter={() => startAutoScroll('right')}
|
||||
onMouseLeave={stopAutoScroll}
|
||||
className="absolute right-2 top-[45%] -translate-y-1/2 w-12 h-12 z-30 bg-black/80 hover:bg-black/95 rounded-full flex items-center justify-center transition-all duration-300 cursor-pointer border border-white/30 shadow-lg opacity-80 hover:!opacity-100"
|
||||
>
|
||||
<ChevronRight className="w-6 h-6 text-white" />
|
||||
</button>
|
||||
|
||||
{/* Scroll container */}
|
||||
<div
|
||||
ref={scrollContainerRef}
|
||||
className="overflow-x-auto scrollbar-hide"
|
||||
style={{
|
||||
scrollbarWidth: 'none',
|
||||
msOverflowStyle: 'none',
|
||||
WebkitScrollbar: { display: 'none' }
|
||||
}}
|
||||
>
|
||||
<div className="flex space-x-4 pb-4 w-max">
|
||||
{/* Create many copies for infinite feel */}
|
||||
{Array.from({ length: 20 }).map((_, copyIndex) =>
|
||||
category.videos.map((video, videoIndex) => (
|
||||
<div key={`${video.id}-${copyIndex}-${videoIndex}`} 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'
|
||||
}}>
|
||||
{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>
|
||||
))
|
||||
).flat()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user