import { useEffect, useRef } from 'react'; import SkeudCard from './SkeudCard'; interface Project { id: string; title: string; subtitle?: string; description: string; image?: string; category: string; status: string; url?: string; stack: string[]; featured?: boolean; } interface Props { projects: Project[]; } export default function Crate({ projects }: Props) { const containerRef = useRef(null); const trackRef = useRef(null); const scrollerRef = useRef(null); useEffect(() => { const container = containerRef.current; const track = trackRef.current; if (!container || !track) return; // Mobile / touch : skip pinned logic, default vertical grid via CSS if (window.matchMedia('(max-width: 767px)').matches) return; if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return; const getTotalScroll = () => track.scrollWidth - window.innerWidth + 100; function onScroll() { if (!container || !track) return; const rect = container.getBoundingClientRect(); const totalScroll = getTotalScroll(); if (totalScroll <= 0) return; if (rect.top <= 0 && rect.bottom > window.innerHeight) { const progress = Math.min(1, Math.max(0, -rect.top / (container.offsetHeight - window.innerHeight))); track.style.transform = `translate3d(${-progress * totalScroll}px, 0, 0)`; } } window.addEventListener('scroll', onScroll, { passive: true }); window.addEventListener('resize', onScroll); onScroll(); return () => { window.removeEventListener('scroll', onScroll); window.removeEventListener('resize', onScroll); }; }, [projects.length]); // Height of container = 100vh * (project count factor) to give scroll room const containerHeightStyle = { height: `${Math.max(100, projects.length * 60)}vh`, }; return ( <> {/* Desktop : pinned horizontal scroll */}
{projects.map((project, i) => ( ))}
end of crate ยท {projects.length} skeuds
{/* Mobile : vertical grid fallback */}
{projects.map((project, i) => ( ))}
); }