diff --git a/client/src/pages/home.tsx b/client/src/pages/home.tsx index 4b89086..8f039c8 100644 --- a/client/src/pages/home.tsx +++ b/client/src/pages/home.tsx @@ -281,11 +281,27 @@ function FeaturedHeroCard({ article, focalPoints }: { article: Article; focalPoi } function FeaturedCarousel({ articles, popular, galleryImages, focalPoints }: { articles: Article[]; popular?: Article[]; galleryImages?: GalleryImage[]; focalPoints?: Record }) { - const hero = articles[0]; - const bottom = articles.slice(1, 3); + const pageSize = 3; + const totalPages = Math.max(1, Math.ceil(Math.min(articles.length, 9) / pageSize)); + const [page, setPage] = useState(0); + const [paused, setPaused] = useState(false); + + const next = useCallback(() => { + setPage((p) => (p + 1) % totalPages); + }, [totalPages]); + + useEffect(() => { + if (paused || totalPages <= 1) return; + const timer = setInterval(next, 8000); + return () => clearInterval(timer); + }, [paused, next, totalPages]); + + const start = page * pageSize; + const hero = articles[start]; + const bottom = articles.slice(start + 1, start + 3); return ( -
+
setPaused(true)} onMouseLeave={() => setPaused(false)}>
@@ -301,6 +317,13 @@ function FeaturedCarousel({ articles, popular, galleryImages, focalPoints }: { a {popular && popular.length > 0 && }
+ {totalPages > 1 && ( +
+ {Array.from({ length: totalPages }).map((_, i) => ( +
+ )}
); } @@ -346,10 +369,10 @@ export default function Home() { ); } - const row2 = articles.slice(3, 5); - const row3 = articles.slice(5, 7); - const remaining = articles.slice(7); - const topStoriesCount = Math.min(12, articles.length); + const carouselEnd = Math.min(9, articles.length); + const row2 = articles.slice(carouselEnd, carouselEnd + 2); + const row3 = articles.slice(carouselEnd + 2, carouselEnd + 4); + const remaining = articles.slice(carouselEnd + 4); const rows: Article[][] = []; for (let i = 0; i < remaining.length; i += 4) { rows.push(remaining.slice(i, i + 4));