"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; import { ScrollArea } from "@/components/ui/scroll-area"; // pastikan ada komponen ini import { Calendar } from "lucide-react"; import Link from "next/link"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; createdByName: string; thumbnailUrl: string; files: { fileUrl: string; file_alt: string }[]; }; export default function News() { const [articles, setArticles] = useState([]); const [recentPosts, setRecentPosts] = useState([]); useEffect(() => { fetchArticles(); fetchRecentPosts(); }, []); async function fetchArticles() { try { const req = { limit: "8", // ambil 8 artikel untuk konten utama page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; const res = await getListArticle(req); setArticles(res?.data?.data || []); } catch (error) { console.error("Gagal memuat artikel utama:", error); } } async function fetchRecentPosts() { try { const req = { limit: "5", // ambil 5 artikel untuk recent posts page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; const res = await getListArticle(req); setRecentPosts(res?.data?.data || []); } catch (error) { console.error("Gagal memuat recent posts:", error); } } return (
{/* Scrollable Left Section */}
{articles.slice(0, 4).map((article) => (
{article.title}

{article.categoryName}

{article.title}

{article.description}

{article.createdByName}{" "}
{new Date(article.createdAt).toLocaleDateString("en-GB", { day: "2-digit", month: "long", year: "numeric", })}
))}
{/* Banner */}
Berita Utama
{/* Artikel kedua */}
{articles.slice(4, 8).map((article) => (
{article.title}

{article.categoryName}

{article.title}

{article.description}

{article.createdByName}{" "}
{new Date(article.createdAt).toLocaleDateString("en-GB", { day: "2-digit", month: "long", year: "numeric", })}
))}
{/* Banner */}
Berita Utama
{/* Pagination (sementara statis, bisa pakai API meta untuk dinamis) */}
...
{/* Fixed Right Section */}

Recent Posts

{recentPosts.map((item) => (
{item.title}

{item.categoryName}

{item.title}

{new Date(item.createdAt).toLocaleDateString("en-GB", { day: "2-digit", month: "long", year: "numeric", })}

))} {/* Ads / Subscribe */}
Iklan 2

Subscribe us to get the latest news!

Iklan 2
); }