"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 } 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 (
{type == "space" && data?.is_headed === 1 && ( )}
router.push("/profile/" + data.mid)} />
handleFollow(isFollow, data?.mid, setIsFollow)} > {data.streamer_ext?.name} {type == "post" && ( {isFollow ? "已关注" : "关注"} )}
{(data?.status === 0 || data?.status === 1) && (
审核中
)} {data?.status === 3 && (

审核未通过,请前往APP编辑。

)}
{!data?.is_zone_moment_unlocked ? (
) : (
)} {!( !data?.is_zone_moment_unlocked && data?.text_visible_range < 999 ) && data.text?.length > 140 && (
setIsOpenText(!isOpenText)} > {isOpenText ? "收起" : "全文"}
)}
{data.media_component && ( )} {type == "space" && !!data.c_type && ( )}
{type == "post" ? (
router.push("/space/person_space_introduce/" + data.mid) } > {data.streamer_ext.is_active_within_a_week ? ( <> {/* {data.streamer_ext.days_elapsed_since_the_last_zones_update < 7 && `空间${ data.streamer_ext.days_elapsed_since_the_last_zones_update === 0 ? "今日" : "new" === 1 ? "昨日" : "new" === 2 ? "前天" : data.streamer_ext.days_elapsed_since_the_last_zones_update + "天前" }有更新`} 空间 */} {formatZoneUpdateTime( data?.streamer_ext ?.days_elapsed_since_the_last_zones_update )} 有更新 ) : ( data?.streamer_ext?.zones?.length !== 0 && (
查看TA的空间
) )}
) : (
{getDays < 3 ? `${ getDays === 0 ? "今日" : "new" === 1 ? "昨日" : "前天" }` : date.getMonth() + 1 + "-" + date.getDate()} {(date.getHours() > 9 ? date.getHours() : "0" + date.getHours()) + ":" + (date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes())}
)}
thumbsUp(data.id, isThumbsUp, setIsThumbsUp, type == "space") } > {isThumbsUp == 1 ? "已赞" : "点赞"}
  • { router.push("/messageDetail"); }} > 举报
  • } trigger="click" placement="left" > ···
    {/*
    */}
    ); }