"use client"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; import { getListArticle } from "@/service/article"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; slug: string; thumbnailUrl?: string; }; export default function ImageCard() { const [articles, setArticles] = useState([]); const [page] = useState(1); const [showData] = useState("6"); const [search] = useState(""); const [selectedCategory, setSelectedCategory] = useState(null); async function initState() { const req = { limit: showData, page, search, categorySlug: "", sort: "desc", isPublish: true, title: search, categoryId: selectedCategory, sortBy: "created_at", }; try { const res = await getListArticle(req); setArticles(res?.data?.data || []); } catch (err) { console.error("Error get article:", err); } } useEffect(() => { initState(); }, []); return (
{articles.map((item) => (
{/* IMAGE */}
{item.title}
{/* CONTENT */}
{/* BADGE + TAG */}
POLRI {item.categoryName}
{/* DATE */}

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

{/* TITLE */}

{item.title}

{/* EXCERPT */}

{item.description}

))}
); }