// components/landing-page/breaking-news.tsx "use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { Calendar } from "lucide-react"; import { getListArticle } from "@/service/article"; import Link from "next/link"; 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 [editorArticles, setEditorArticles] = useState([]); const [newsArticles, setNewsArticles] = useState([]); const [activeTab, setActiveTab] = useState< "trending" | "comments" | "latest" >("trending"); useEffect(() => { fetchArticles(); }, []); async function fetchArticles() { try { const req = { limit: "8", 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 breaking news:", error); } } useEffect(() => { fetchEditorArticles(); }, []); async function fetchEditorArticles() { try { const req = { limit: "6", // jumlah artikel yg ditampilkan page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; const res = await getListArticle(req); setEditorArticles(res?.data?.data || []); setNewsArticles(res?.data?.data || []); } catch (error) { console.error("Gagal memuat Editor's Pick:", error); } } const mainArticle = articles[0]; const sideArticles = articles.slice(1, 5); const popularArticles = articles.slice(1, 5); return (
{mainArticle && (
{/* LEFT - Image */}
{mainArticle.title}
{/* RIGHT - Content */}
{mainArticle.categoryName?.toUpperCase()}

{mainArticle.title}

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

{mainArticle.description}

)}
Kolom PPS

Editor's Pick

{editorArticles?.map((article) => { const imageUrl = article.thumbnailUrl || article.files?.[0]?.fileUrl || "/placeholder.png"; const category = article.categoryName || article.categories?.[0]?.title || "NEWS"; return (
{/* Image */}
{article.title} {category.toUpperCase()}
{/* Title */}

{article.title}

{/* Date */}
{new Date(article.createdAt).toLocaleDateString( "en-GB", { day: "2-digit", month: "long", year: "numeric", } )}
); })}
Kolom PPS
{/* News Index Section */}

News Index

{newsArticles?.map((article) => { const imageUrl = article.thumbnailUrl || article.files?.[0]?.fileUrl || "/placeholder.png"; return (
{/* LEFT - Image */}
{article.title}
{/* RIGHT - Content */}

{article.title}

{article.createdByName || "DODDODYDOD"}
{new Date(article.createdAt).toLocaleDateString( "en-GB", { day: "2-digit", month: "long", year: "numeric", } )}
0

{article.description}

); })}
{/* RIGHT - Tabs + Side Articles */}
{/* Tabs */}
{["trending", "comments", "latest"].map((tab) => ( ))}
{/* List */}
{sideArticles.map((a) => (
{a.title}

{a.title}

{new Date(a.createdAt).toLocaleDateString("en-GB", { day: "2-digit", month: "long", year: "numeric", })}
))}
Berita Utama
Berita Utama
{/* Follow Us Section */}

Follow Us

140 Followers
643 Followers
{/* Popular News Section */}

Popular News

{/* Artikel Utama (Top 1) */} {popularArticles.length > 0 && (
{popularArticles[0].title}

{popularArticles[0].title}

01
154 Shares
)} {/* Artikel 2 - 5 */}
{popularArticles.slice(1, 5).map((a, i) => (
{/* Nomor Urut */}
{String(i + 2).padStart(2, "0")}
{/* Judul & Info */}

{a.title}

{154 - i} Shares
))}
{/* Banner Slot */}
KOLOM PPS
); }