"use client"; import { getListArticle } from "@/service/article"; import { Timer } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useRef, useState } from "react"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; slug: string; createdByName: string; thumbnailUrl: string; categories: { title: string; }[]; files: { fileUrl: string; file_alt: string; }[]; }; export default function Beranda() { 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() { // loading(); 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); } finally { // close(); } } const scrollRef = useRef(null); const scrollLeft = () => { if (scrollRef.current) { scrollRef.current.scrollBy({ left: -240, behavior: "smooth" }); } }; const scrollRight = () => { if (scrollRef.current) { scrollRef.current.scrollBy({ left: 240, behavior: "smooth" }); } }; return (
{articles.map((article) => (
{article.title}

{article.title}

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

))}
); }