"use client"; import React, { useEffect, useState,useRef } from "react"; import { Image, ImageViewer, Dialog } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleUp, faClose } from "@fortawesome/free-solid-svg-icons"; import { useRouter } from "next/navigation"; import baseRequest from "@/utils/baseRequest"; import Player from "next-video/player"; export default function Photos({ isUnlocked, mediaVisibleRange, mediaAmount, media, type, data, }) { const [seeAllPhotos, setSeeAllPhotos] = useState(false); const [currentPhotos, setCurrentPhotos] = useState([]); const [photos, setPhotos] = useState([]); const currentIndex = useRef(); const router = useRouter(); const base = baseRequest(); useEffect(() => { if (media) { let imgArr = media.images.map((item) => ({ type: "img", url: item.urls?.[0], })); let videoArr = media.videos.map((item) => ({ type: "video", url: item.cover_urls?.[0], mp4: item.urls?.[0], })); let arr = [...imgArr, ...videoArr]; let newPhotos = [...arr]; if (mediaAmount && !isUnlocked) { console.log("newPhotos", newPhotos); newPhotos = Array(mediaAmount) .fill(null) .map((item, index) => { return newPhotos[index] && mediaVisibleRange ? newPhotos[index] : { mp4: newPhotos[0]?.type === "video", url: newPhotos[0]?.url, type: "hid", }; }); } setPhotos(newPhotos); if (newPhotos.length > 9) { newPhotos = newPhotos.slice(0, 9); } // console.log("newPhotos", newPhotos); setCurrentPhotos(newPhotos); } }, [media]); const showPhotos = (photos, index) => { currentIndex.current=index; const mediaDom = document.createElement("div"); mediaDom.style.width = "100vw"; document.body.appendChild(mediaDom); mediaDom.className = `${ photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom" }`; const interval = setInterval(() => { const bodyBox = document.getElementsByClassName("photos-bodyBox")[0]; if(bodyBox){ bodyBox.firstChild.lastChild.style.transform = `translateX(-${ (currentIndex.current) * (window.innerWidth + 16) }px)`; // console.log(bodyBox.firstChild.lastChild.style.transform); } }, 400); ImageViewer.Multi.show({ images: photos.map((item) => item?.url), defaultIndex: index, renderFooter: (image, index) => { return renderFooter(photos[index]?.type == "hid", mediaDom); }, getContainer: mediaDom, onIndexChange: (index) => { currentIndex.current=index; mediaDom.className = `${ photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom" }`; }, afterClose: () => { mediaDom.remove(); clearInterval(interval); }, classNames: { body: "photos-bodyBox" }, }); }; const handleShowVideo = (video) => { Dialog.className = "videoMask"; Dialog.show({ title: "", content: (