// 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"; import Link from "next/link"; import { getAdvertise } from "@/service/advertisement"; type Article = { id: number; title: string; description: string; categoryName: string; slug: string; createdAt: string; createdByName: string; thumbnailUrl: string; categories: { title: string }[]; files: { fileUrl: string; file_alt: string }[]; }; type Advertise = { id: number; title: string; description: string; placement: string; contentFileUrl: string; redirectLink: string; }; export default function Header() { const [articles, setArticles] = useState([]); const [showData, setShowData] = useState("5"); const [bannerAd, setBannerAd] = useState(null); useEffect(() => { initStateAdver(); }, []); async function initStateAdver() { const req = { limit: 100, page: 1, sort: "desc", sortBy: "created_at", isPublish: true, }; try { const res = await getAdvertise(req); const data: Advertise[] = res?.data?.data || [1]; // filter iklan dengan placement = "banner" const banner = data.find((ad) => ad.placement === "jumbotron"); if (banner) { setBannerAd(banner); } } catch (err) { console.error("Error fetching advertisement:", err); } } 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 */}
); }