"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; 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 (

PEMBANGUNAN

{articles.length === 0 ? (

Memuat berita...

) : (
{/* === LEFT COLUMN === */} {leftMain && (
{leftMain.title} {leftMain.categories?.[0]?.title}

{leftMain.title}

by {leftMain.customCreatorName || leftMain.createdByName} ·{" "} {formatDate(leftMain.createdAt)}

{leftMain.description}

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

{item.title}

{formatDate(item.createdAt)}

))}
)} {/* === CENTER COLUMN === */} {centerMain && (
{centerMain.title} {centerMain.categories?.[0]?.title}

{centerMain.title}

by {centerMain.customCreatorName || centerMain.createdByName}{" "} · {formatDate(centerMain.createdAt)}

{centerMain.description}

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

{item.title}

{formatDate(item.createdAt)}

))}
)} {/* === RIGHT COLUMN === */} {rightMain && (
{rightMain.title} {rightMain.categories?.[0]?.title}

{rightMain.title}

by {rightMain.customCreatorName || rightMain.createdByName} ·{" "} {formatDate(rightMain.createdAt)}

{rightMain.description}

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

{item.title}

{formatDate(item.createdAt)}

))}
)}
)}
Berita Utama
); }