"use client"; import React, { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; createdByName: string; thumbnailUrl: string; categories: { title: string; }[]; files: { fileUrl: string; file_alt: string; }[]; }; export default function BreakingNews() { const [articles, setArticles] = useState([]); const [popular, setPopular] = useState([]); useEffect(() => { fetchArticles(); fetchPopular(); }, []); async function fetchArticles() { try { const req = { limit: "5", 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:", error); } } async function fetchPopular() { try { const req = { limit: "5", page: 1, search: "", categorySlug: "", sort: "", isPublish: true, sortBy: "", }; const res = await getListArticle(req); setPopular(res?.data?.data || []); } catch (error) { console.error("Gagal memuat artikel populer:", error); } } return (
{/* Kiri - Breaking News */}
{articles.map((item) => (
{item.title}

{item.title}

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

{item.description}

))}
{/* Tengah - Browse Categories & Topics (dummy) */}

BROWSE BY CATEGORIES

  • Berita Opini
  • Berita Populer
  • Berita Terkini
  • Jaga Negeri
  • National
  • Politics
  • Ragam Nusantara

BROWSE BY TOPICS

{[ "#GIIAS2025", "#mdtranscorp", "2018 League", "Bali United", "Chopper Bike", ].map((topic, i) => ( {topic} ))}
{/* Kanan - Popular News */}

POPULAR NEWS

{popular.length > 0 && (
{/* Item pertama tampil besar */}
{
{popular[0]?.title}
01
{/* Item sisanya */}
{popular.slice(1).map((item, i) => (
0{i + 2}
{item.title}

0 Shares

))}
)} {/* Advert */}
Advertisement
); }