"use client"; import { getListArticle } from "@/service/article"; import { ChevronDown } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; type Article = { id: number; title: string; description: string; categoryName: string; slug: string; createdAt: string; publishedAt: string; createdByName: string; customCreatorName: string; thumbnailUrl: string; categories: { title: string }[]; files: { fileUrl: string; file_alt: string }[]; }; export default function OpinionNews() { const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [articles, setArticles] = useState([]); const [showData, setShowData] = useState("6"); const [search] = useState(""); const [selectedCategories] = useState(""); const [startDateValue] = useState({ startDate: null, endDate: null, }); useEffect(() => { initState(); }, [page, showData, startDateValue, selectedCategories]); async function initState() { const req = { limit: showData, page, search, categorySlug: Array.from(selectedCategories).join(","), 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); } } return (
{/* TITLE */}

BERITA OPINI

{/* GRID 4 KOLOM */}
{articles.slice(0, 4).map((item) => (
{/* GAMBAR */}
{item.title} {/* BADGE CATEGORY DI DALAM GAMBAR */}
{item.categoryName || "Kategori"}
{/* JUDUL */}

{item.title}

{/* AUTHOR + DATE */}
By {item.customCreatorName || item.createdByName || "Admin"} - {new Date(item.publishedAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })}
))}
Kolom PPS
); }