"use client"; import React, { useEffect, useState, useMemo,useCallback } from "react"; import Photos from "../Photos"; import { useRouter } from "next/navigation"; import PaySpacePost from "../PaySpacePost"; import { Image, Popover, Divider, Toast } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleRight } from "@fortawesome/free-solid-svg-icons"; import { handleFollow, thumbsUp } from "@/api/public"; import { get } from "@/utils/storeInfo"; import { Inter } from "next/font/google"; const inter = Inter({ subsets: ["latin"] }); export default function PostItem({ type, follow, date = new Date(), data = {}, }) { const router = useRouter(); const [isOpenText, setIsOpenText] = useState(false); const [isFollow, setIsFollow] = useState(data.is_followed); const [isThumbsUp, setIsThumbsUp] = useState( data?.is_thumbed_up || data?.is_zone_moment_thumbed_up ); //判断是否是发帖人 const [isCreator, setIsCreator] = useState(false); useEffect(() => { const account = get("account"); if (account?.mid === data.mid) setIsCreator(true); return () => { router.prefetch("/profile/" + data.mid); }; }, []); const getDays = useMemo(() => { const today = new Date(); const days = Math.floor((today - data.ct) / (1000 * 60 * 60 * 24)); return days; }, []); function findLinksInText(text) { // 定义一个正则表达式来匹配URL // 注意:这个正则表达式可能无法匹配所有可能的URL,但可以匹配大部分常见的格式 var urlPattern = /https?:\/\/[^\s\/$.?#].[^\s]*/g; // 使用正则表达式的exec或match方法查找匹配项 // exec在全局搜索中需要循环调用,而match在全局模式下直接返回所有匹配项 var matches = text?.match(urlPattern); // // 如果没有找到匹配项,返回空数组 // if (!matches) { // return text; // } if (matches) { matches?.forEach((el) => { // console.log("index", text.indexOf(el)); text = text.replace( el, `#网页链接` ); }); // console.log("matches", matches); // console.log("text", text); } // 返回找到的链接数组 return text; } const formatZoneUpdateTime = useCallback((time) => { if (time === 0) return "今日"; if (time === 1) return "昨日"; return `${time}日前`; }, []); return (
审核未通过,请前往APP编辑。
)}