"use client"; import { getListArticle } from "@/service/article"; import { Clock } from "lucide-react"; import Image from "next/image"; import { useEffect, useState } from "react"; type postsData = { id: number; title: string; description: string; categoryName: string; createdAt: string; createdByName: string; thumbnailUrl: string; categories: { title: string; }[]; files: { file_url: string; file_alt: string; }[]; }; export default function Beranda() { const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [posts, setPosts] = useState([]); const [showData, setShowData] = useState("5"); const [search, setSearch] = useState(""); const [selectedCategories, setSelectedCategories] = useState(""); const [startDateValue, setStartDateValue] = useState({ startDate: null, endDate: null, }); useEffect(() => { initState(); }, [page, showData, startDateValue, selectedCategories]); async function initState() { // loading(); const req = { limit: showData, page, search, categorySlug: Array.from(selectedCategories).join(","), sort: "desc", sortBy: "created_at", }; try { const res = await getListArticle(req); setPosts(res?.data?.data || []); setTotalPage(res?.data?.meta?.totalPage || 1); } finally { // close(); } } return (

Football

{posts.slice(1, 5).map((posts, index) => (
{posts.title}
{posts.categories?.[0]?.title}

{posts.title}

{posts.createdByName} -{" "} {new Date(posts.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })}
))}
Berita Utama
); }