From db5ec8b74ca8f41d5eff6f91390f1535bd623fa0 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Sat, 28 Feb 2026 17:16:06 +0000 Subject: [PATCH] Update the featured articles section to automatically rotate and display the latest articles Modify the `FeaturedSection` component to include auto-rotation functionality, displaying up to 6 articles in a carousel. Update the `getFeaturedArticles` database query to retrieve the latest 6 articles instead of only those marked as featured. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 413891e8-d784-4bea-b9f5-91a5a68316b4 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: e6e519fc-41a3-463e-88ea-3bde9e02f7f4 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/413891e8-d784-4bea-b9f5-91a5a68316b4/kmpcO4B Replit-Helium-Checkpoint-Created: true --- client/src/pages/home.tsx | 50 +++++++++++++++++++++++++++++++++++---- server/storage.ts | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/client/src/pages/home.tsx b/client/src/pages/home.tsx index 159d4ba..e3aa7e8 100644 --- a/client/src/pages/home.tsx +++ b/client/src/pages/home.tsx @@ -8,15 +8,42 @@ import { Skeleton } from "@/components/ui/skeleton"; import { Button } from "@/components/ui/button"; import Header from "@/components/header"; import Footer from "@/components/footer"; +import { useState, useEffect, useCallback } from "react"; function FeaturedSection({ articles }: { articles: Article[] }) { - if (articles.length === 0) return null; + const pool = articles.slice(0, 6); + const totalPages = Math.ceil(pool.length / 3); + const [page, setPage] = useState(0); + const [paused, setPaused] = useState(false); - const hero = articles[0]; - const side = articles.slice(1, 3); + const next = useCallback(() => { + setPage((p) => (p + 1) % totalPages); + }, [totalPages]); + + useEffect(() => { + if (paused || totalPages <= 1) return; + const timer = setInterval(next, 5000); + return () => clearInterval(timer); + }, [paused, next, totalPages]); + + if (pool.length === 0) return null; + + const start = page * 3; + const visible = pool.slice(start, start + 3); + while (visible.length < 3 && pool.length >= 3) { + visible.push(pool[visible.length % pool.length]); + } + + const hero = visible[0]; + const side = visible.slice(1, 3); return ( -
+
setPaused(true)} + onMouseLeave={() => setPaused(false)} + >
+ + {totalPages > 1 && ( +
+ {Array.from({ length: totalPages }).map((_, i) => ( +
+ )}
); } diff --git a/server/storage.ts b/server/storage.ts index 8b59771..7a2c320 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -31,7 +31,7 @@ export class DatabaseStorage implements IStorage { } async getFeaturedArticles(): Promise { - return db.select().from(articles).where(eq(articles.featured, true)).orderBy(desc(articles.publishedAt)).limit(3); + return db.select().from(articles).orderBy(desc(articles.publishedAt)).limit(6); } async getPopularArticles(limit: number): Promise {