'use client' import { useRef, useEffect } from 'react' import { motion, useAnimationFrame } from 'framer-motion' import Image from 'next/image' import { Project } from '@/data/projects' interface ProjectSliderProps { projects: Project[] } export default function ProjectSlider({ projects }: ProjectSliderProps) { const containerRef = useRef(null) // Duplicate projects for seamless infinite loop const doubledProjects = [...projects, ...projects] // Speed of the automatic scroll const speed = 0.8 useAnimationFrame(() => { if (!containerRef.current) return containerRef.current.scrollLeft += speed const firstHalfWidth = containerRef.current.scrollWidth / 2 if (containerRef.current.scrollLeft >= firstHalfWidth) { containerRef.current.scrollLeft = 0 } }) const handleWheel = (e: React.WheelEvent) => { if (!containerRef.current) return containerRef.current.scrollLeft += e.deltaY } return (
{doubledProjects.map((project, idx) => (
{/* Image Container */}
{project.title}
{/* Project Info */}
{project.year} — {project.location}
{project.title}
))}
) }