"use client"; import Link from "next/link"; import { useCallback, useEffect, useRef, useState } from "react"; /** * Horizontal, scroll-snap slider for the home page "latest news" row. Keeps the * exact article-card markup from the server page; the cards are passed in as a * pre-shaped list so this client component carries no prisma/i18n dependency. * Prev/next buttons scroll the snap track by one viewport-ish step and disable * themselves at the ends. */ export type SliderArticle = { slug: string; title: string; image: string; excerpt: string; }; export function ArticleSlider({ articles }: { articles: SliderArticle[] }) { const trackRef = useRef(null); const [atStart, setAtStart] = useState(true); const [atEnd, setAtEnd] = useState(false); const updateEdges = useCallback(() => { const el = trackRef.current; if (!el) return; const maxScroll = el.scrollWidth - el.clientWidth; setAtStart(el.scrollLeft <= 1); setAtEnd(el.scrollLeft >= maxScroll - 1); }, []); useEffect(() => { updateEdges(); window.addEventListener("resize", updateEdges); return () => window.removeEventListener("resize", updateEdges); }, [updateEdges]); const scrollByDir = useCallback((dir: 1 | -1) => { const el = trackRef.current; if (!el) return; // Step by roughly one card width (incl. gap) so snapping lands cleanly. const step = Math.max(el.clientWidth * 0.8, 260); el.scrollBy({ left: dir * step, behavior: "smooth" }); }, []); return (
{articles.map((a) => (
{a.image ? ( // biome-ignore lint/performance/noImgElement: external article image ) : (
)}

{a.title}

{a.excerpt}

))}
); }