"use client"; import { Button, Card, CardFooter, CircularProgress, Image, ScrollShadow, Skeleton, } from "@heroui/react"; import { ChevronLeftIcon, ChevronRightIcon, EyeIcon } from "../icons"; import { Swiper, SwiperSlide, useSwiper } from "swiper/react"; import "swiper/css"; import "swiper/css/navigation"; import { Autoplay, Pagination, Navigation, Controller } from "swiper/modules"; import Link from "next/link"; import GPRKominfo from "../ui/social-media/gpr-kominfo"; import { useEffect, useState } from "react"; import { getListArticle } from "@/services/article"; import { convertDateFormat, textEllipsis } from "@/utils/global"; import { useTranslations } from "next-intl"; import { data } from "autoprefixer"; import { Controller as FormController } from "react-hook-form"; import { Nabla } from "next/font/google"; export default function HeaderNews() { const [article, setArticle] = useState([]); // const t = useTranslations("Landing"); const [selectedTab, setSelectedTab] = useState("media"); const [hotNews, setHotNews] = useState([]); const [banner, setBanner] = useState([]); // useEffect(() => { // }, []); useEffect(() => { getArticle(); getBanner(); getHotNews(); }, []); async function getArticle() { const req = { page: 1, search: "", limit: "10", sort: "desc", isPublish: true, }; const response = await getListArticle(req); setArticle(response?.data?.data); } async function getBanner() { const req = { page: 1, search: "", limit: "10", sort: "desc", isPublish: true, isBanner: true, }; const response = await getListArticle(req); setBanner(response?.data?.data); } async function getHotNews() { const req = { page: 1, search: "", limit: "10", sort: "desc", categoryIds: "791,802", isPublish: true, }; const response = await getListArticle(req); setHotNews(response?.data?.data); } const [portraitMap, setPortraitMap] = useState({}); const handleImageLoad = (e: any, index: number) => { const { naturalWidth, naturalHeight } = e.target; const isPortrait = naturalHeight > naturalWidth; setPortraitMap((prev: any) => ({ ...prev, [index]: isPortrait, })); }; return (
{hotNews?.length > 0 ? ( { swiper.navigation.nextEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[32px]", "!h-[32px]" ); swiper.navigation.prevEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[32px]", "!h-[32px]" ); }} > {hotNews?.map((newsItem: any, index: number) => (
headernews handleImageLoad(e, index)} src={ newsItem?.thumbnailUrl === "" ? "/no-image.jpg" : newsItem?.thumbnailUrl + "?isBanner=true" } className={`!object-cover !rounded-none ${ portraitMap[index] ? "!w-auto object-cover mx-auto" : "!w-[90vw]" } !h-[200px] md:!h-[400px]`} />

{textEllipsis(newsItem.title, 40)}

{convertDateFormat(newsItem.createdAt)} WIB

{newsItem.viewCount === null ? 0 : newsItem.viewCount}

))}
) : (
)}

Hot Topik

{hotNews?.length > 0 ? ( hotNews?.map((data: any, index: number) => (
{textEllipsis(data.title, 40)} {data.title}

{convertDateFormat(data.createdAt)} WIB

{data.viewCount === null ? 0 : data.viewCount}

)) ) : (
)}
{hotNews?.length > 0 ? ( { swiper.navigation.nextEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); swiper.navigation.prevEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); }} > {hotNews?.map((newsItem: any, index: number) => (
headernews handleImageLoad(e, index)} src={ newsItem?.thumbnailUrl === "" ? "/no-image.jpg" : newsItem?.thumbnailUrl + "?isBanner=true" } className={`!object-cover !rounded-none ${ portraitMap[index] ? "!w-auto object-cover mx-auto" : "!w-full" } !h-[500px]`} />

{textEllipsis(newsItem.title, 60)}

{textEllipsis(newsItem.title, 200)}

{convertDateFormat(newsItem.createdAt)} WIB

{newsItem.viewCount === null ? 0 : newsItem.viewCount}

))}
) : (
)}
{selectedTab === "media" ? (
{article?.length > 0 ? ( article?.map((list: any, index: number) => (

{list?.title}

{convertDateFormat(list?.createdAt)} WIB

{list?.viewCount === null ? 0 : list?.viewCount}

)) ) : (
)}
) : (
IKLAN LAYANAN MASYARAKAT DIVHUMAS POLRI - POLRI PRESISI UNTUK INDONESIA ILM DIVHUMAS POLRI - POLRI PRESISI MENGAWAL PROSES VAKSINASI UNTUK MENGATASI PANDEMI COVID 19 IKLAN LAYANAN MASYARAKAT DIVHUMAS POLRI - INDONESIA MENOLAK RADIKALISME IKLAN LAYANAN MASYARAKAT DIVHUMAS POLRI - BHABINKAMTIBMAS SAHABAT MASYARAKAT
)}
); }