"use client"; import { Facebook, Instagram, RefreshCcwIcon, ThumbsUpIcon, Twitter, UserRoundPlus, Youtube, } from "lucide-react"; import Image from "next/image"; import { useEffect, useState } from "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 News() { const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [articles, setArticles] = 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() { 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 (error) { console.error("Failed to fetch articles:", error); } } function truncateText(text: string, wordLimit: number) { const words = text.split(" "); if (words.length <= wordLimit) return text; return words.slice(0, wordLimit).join(" ") + "..."; } return (
{/* Left: News Section */}

BERITA TERKINI

{articles.map((item) => (
{item.title}
{item.categoryName || "Berita Terkini"}

{item.title}

by {item.createdByName || "admin"}{" "} {new Date(item.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })} 0

{truncateText(item.description, 50)}

))}
{/* Load more button */}
{page < totalPage && ( )}
{/* Banner */}
Berita Utama
{/* Right Sidebar */}
); }