// components/landing-page/header.tsx "use client"; import Image from "next/image"; import { Calendar, Eye, MessageSquare } from "lucide-react"; import { useEffect, useState } from "react"; import { getListArticle } from "@/service/article"; 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 Header() { const [articles, setArticles] = useState([]); const [showData, setShowData] = useState("5"); useEffect(() => { fetchArticles(); }, [showData]); async function fetchArticles() { try { const req = { limit: showData, page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; const res = await getListArticle(req); setArticles(res?.data?.data || []); } catch (error) { console.error("Gagal memuat artikel:", error); } } return (
{/* LEFT MAIN CONTENT */}
{/* Bagian 3 artikel di atas */}
{articles.slice(0, 3).map((post) => (
{post.title}
{post.categoryName || post.categories?.[0]?.title}

{post.title}

{" "} {new Date(post.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })} {/* belum ada views di API */} 0 {" "} {/* belum ada comments */}0
))}
{/* Bagian 2 artikel di bawah */}
{articles.slice(3, 5).map((post) => (
{post.title}
{post.categoryName || post.categories?.[0]?.title}

{post.title}

{" "} {new Date(post.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })} 0 0
))}
{/* SIDEBAR */}
); }