"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; import Link from "next/link"; type Article = { id: number; title: string; description: string; categoryName: string; slug: string; createdAt: string; createdByName: string; customCreatorName: string; thumbnailUrl: string; categories: { title: string }[]; files: { fileUrl: string; file_alt: string }[]; }; export default function Development() { const [articles, setArticles] = useState([]); const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); useEffect(() => { initState(); }, [page]); async function initState() { const req = { limit: "10", page, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; try { const res = await getListArticle(req); setArticles(res?.data?.data || []); setTotalPage(res?.data?.meta?.totalPage || 1); } catch (err) { console.error("Error fetching articles:", err); } } // Format tanggal ke gaya lokal const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleDateString("id-ID", { day: "2-digit", month: "long", year: "numeric", }); }; // Mapping struktur seperti dummy sebelumnya const leftMain = articles[0]; const leftList = articles.slice(1, 4); const centerMain = articles[4]; const centerList = articles.slice(5, 8); const rightMain = articles[8]; const rightList = articles.slice(9, 12); return (

JAGA NEGERI

{articles.slice(0, 6).map((item) => (
{item.title}

BERITA OPINI

{item.title}

By{" "} {item.customCreatorName}

{new Date(item.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })}

))}
Berita Utama
); }