"use client"; import { convertDateFormat, formatMonthString, formatTextToHtmlTag, } from "@/utils/global"; import { CalendarIcon, ChevronLeftIcon, ChevronRightIcon, ClockIcon, EyeIcon, EyeIconMdi, FacebookIcon, SquareFacebookIcon, SquareLinkedInIcon, SquareWhatsappIcon, SquareXIcon, UserIcon, } from "../icons"; import { Button } from "@heroui/button"; import { useParams, usePathname } from "next/navigation"; import Link from "next/link"; import { useEffect, useState } from "react"; import { image } from "@heroui/theme"; import Cookies from "js-cookie"; import { saveActivity } from "@/services/activity-log"; import { Accordion, AccordionItem, Image } from "@heroui/react"; const token = Cookies.get("access_token"); const uid = Cookies.get("uie"); export default function DetailNews(props: { data: any; listArticle: any }) { const { data, listArticle } = props; const [prevArticle, setPrevArticle] = useState(""); const [nextArticle, setNextArticle] = useState(""); const [imageNow, setImageNow] = useState(0); const pathname = usePathname(); const params = useParams(); const id: any = params?.id; const shareText = "Humas Polri"; const handleShare = async (platform: string) => { let shareLink = ""; const urls = "https://new-humas.polri.go.id/" + pathname; let req: any = { activityTypeId: 3, url: "https://new-humas.polri.go.id/" + pathname, articleId: Number(id?.split("-")[0]), }; if (uid) { req.userId = Number(uid); } const resActivity = await saveActivity(req, token); switch (platform) { case "facebook": shareLink = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent( urls )}`; break; case "x": shareLink = `https://x.com/intent/tweet?url=${encodeURIComponent( urls )}&text=${encodeURIComponent(shareText)}`; break; case "linkedin": shareLink = `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent( urls )}`; break; case "whatsapp": shareLink = `https://wa.me/?text=${encodeURIComponent( shareText + " " + urls )}`; break; default: break; } const popupWidth = 800; const popupHeight = 600; const left = window.screenX + (window.innerWidth - popupWidth) / 2; const top = window.screenY + (window.innerHeight - popupHeight) / 2; window.open( shareLink, "_blank", `width=${popupWidth},height=${popupHeight},top=${top},left=${left},resizable=no,scrollbars=no,toolbar=no,menubar=no,status=no` ); }; useEffect(() => { if (listArticle) { const index = listArticle?.findIndex( (item: any) => item?.id === data?.id ); if (index - 1 == -1) { setPrevArticle(""); } else { const prevString = `${listArticle[index - 1]?.id}-${ listArticle[index - 1]?.slug }`; setPrevArticle(prevString); } if (index + 1 == listArticle?.length) { setNextArticle(""); } else { const nextString = `${listArticle[index + 1]?.id}-${ listArticle[index + 1]?.slug }`; setNextArticle(nextString); } } }, [data, listArticle]); function removeImgTags(htmlString?: { __html: string }) { const parser = new DOMParser(); const doc = parser.parseFromString(String(htmlString?.__html), "text/html"); const images = doc.querySelectorAll("img"); images.forEach((img) => img.remove()); return { __html: doc.body.innerHTML }; } return (
{data?.title}
{data?.createdByName}
{formatMonthString(data?.updatedAt)}
{`${new Date(data?.updatedAt) .getHours() .toString() .padStart(2, "0")}:${new Date(data?.updatedAt) .getMinutes() .toString() .padStart(2, "0")}`}
TAGS
Selanjutnya