"use client"; import React, { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; import Link from "next/link"; import { usePathname } from "next/navigation"; 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 BumnNews() { const [articles, setArticles] = useState([]); const [popular, setPopular] = useState([]); const pathname = usePathname(); // ⬅️ "/bumn-news" misalnya const categoryName = pathname .split("/") .filter(Boolean) .pop() ?.replace(/-/g, " ") // ubah slug jadi teks rapi ?.replace(/\b\w/g, (c) => c.toUpperCase()) || "News"; useEffect(() => { fetchArticles(); fetchPopular(); }, []); 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 */}
{/* Breadcrumb */}
Home {">"} Category {">"} {categoryName}

{categoryName}

{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 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
); }