2024-06-25 20:18:37 +08:00
|
|
|
|
"use client";
|
|
|
|
|
|
2024-08-09 22:10:02 +08:00
|
|
|
|
import React, { useEffect, useState, useMemo, useCallback } from "react";
|
2024-06-25 20:18:37 +08:00
|
|
|
|
import Photos from "../Photos";
|
2024-06-26 19:46:31 +08:00
|
|
|
|
import { useRouter } from "next/navigation";
|
2024-06-29 12:07:37 +08:00
|
|
|
|
import PaySpacePost from "../PaySpacePost";
|
2024-08-06 16:21:34 +08:00
|
|
|
|
import { Image, Popover, Divider, Toast } from "antd-mobile";
|
2024-07-03 19:59:39 +08:00
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
|
import { faAngleRight } from "@fortawesome/free-solid-svg-icons";
|
2024-07-06 11:05:19 +08:00
|
|
|
|
import { handleFollow, thumbsUp } from "@/api/public";
|
2024-07-11 23:57:26 +08:00
|
|
|
|
import { get } from "@/utils/storeInfo";
|
2024-07-23 20:56:25 +08:00
|
|
|
|
import { Inter } from "next/font/google";
|
|
|
|
|
const inter = Inter({ subsets: ["latin"] });
|
2024-06-29 12:07:37 +08:00
|
|
|
|
export default function PostItem({
|
|
|
|
|
type,
|
|
|
|
|
follow,
|
|
|
|
|
date = new Date(),
|
2024-07-03 19:59:39 +08:00
|
|
|
|
data = {},
|
2024-06-29 12:07:37 +08:00
|
|
|
|
}) {
|
2024-06-26 19:46:31 +08:00
|
|
|
|
const router = useRouter();
|
2024-06-27 18:34:03 +08:00
|
|
|
|
const [isOpenText, setIsOpenText] = useState(false);
|
2024-07-06 11:05:19 +08:00
|
|
|
|
const [isFollow, setIsFollow] = useState(data.is_followed);
|
2024-07-11 23:57:26 +08:00
|
|
|
|
const [isThumbsUp, setIsThumbsUp] = useState(
|
|
|
|
|
data?.is_thumbed_up || data?.is_zone_moment_thumbed_up
|
|
|
|
|
);
|
2024-07-06 11:05:19 +08:00
|
|
|
|
//判断是否是发帖人
|
|
|
|
|
const [isCreator, setIsCreator] = useState(false);
|
2024-06-27 18:34:03 +08:00
|
|
|
|
useEffect(() => {
|
2024-07-06 11:05:19 +08:00
|
|
|
|
const account = get("account");
|
2024-08-06 16:21:34 +08:00
|
|
|
|
if (account?.mid === data.mid) setIsCreator(true);
|
2024-06-27 18:34:03 +08:00
|
|
|
|
return () => {
|
2024-07-11 23:57:26 +08:00
|
|
|
|
router.prefetch("/profile/" + data.mid);
|
2024-06-27 18:34:03 +08:00
|
|
|
|
};
|
|
|
|
|
}, []);
|
2024-06-29 12:07:37 +08:00
|
|
|
|
const getDays = useMemo(() => {
|
|
|
|
|
const today = new Date();
|
2024-07-10 16:50:53 +08:00
|
|
|
|
const days = Math.floor((today - data.ct) / (1000 * 60 * 60 * 24));
|
2024-06-29 12:07:37 +08:00
|
|
|
|
return days;
|
|
|
|
|
}, []);
|
2024-07-17 20:30:33 +08:00
|
|
|
|
function findLinksInText(text) {
|
|
|
|
|
// 定义一个正则表达式来匹配URL
|
|
|
|
|
// 注意:这个正则表达式可能无法匹配所有可能的URL,但可以匹配大部分常见的格式
|
|
|
|
|
var urlPattern = /https?:\/\/[^\s\/$.?#].[^\s]*/g;
|
|
|
|
|
|
|
|
|
|
// 使用正则表达式的exec或match方法查找匹配项
|
|
|
|
|
// exec在全局搜索中需要循环调用,而match在全局模式下直接返回所有匹配项
|
2024-07-22 16:41:33 +08:00
|
|
|
|
var matches = text?.match(urlPattern);
|
2024-07-17 20:30:33 +08:00
|
|
|
|
|
|
|
|
|
// // 如果没有找到匹配项,返回空数组
|
|
|
|
|
// if (!matches) {
|
|
|
|
|
// return text;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
|
matches?.forEach((el) => {
|
2024-07-22 16:41:33 +08:00
|
|
|
|
// console.log("index", text.indexOf(el));
|
2024-07-17 20:30:33 +08:00
|
|
|
|
text = text.replace(
|
|
|
|
|
el,
|
2024-08-21 11:30:19 +08:00
|
|
|
|
`<a className="text-btn" href="${el}" target="_blank">#网页链接</a>`
|
2024-07-17 20:30:33 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2024-07-22 16:41:33 +08:00
|
|
|
|
// console.log("matches", matches);
|
2024-08-05 18:59:30 +08:00
|
|
|
|
// console.log("text", text);
|
2024-07-17 20:30:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回找到的链接数组
|
|
|
|
|
return text;
|
|
|
|
|
}
|
2024-08-02 22:12:54 +08:00
|
|
|
|
const formatZoneUpdateTime = useCallback((time) => {
|
|
|
|
|
if (time === 0) return "今日";
|
|
|
|
|
if (time === 1) return "昨日";
|
|
|
|
|
return `${time}日前`;
|
|
|
|
|
}, []);
|
2024-06-25 20:18:37 +08:00
|
|
|
|
return (
|
2024-06-29 12:07:37 +08:00
|
|
|
|
<div>
|
2024-07-11 23:57:26 +08:00
|
|
|
|
{type == "space" && data?.is_headed === 1 && (
|
2024-07-31 14:46:03 +08:00
|
|
|
|
<Image
|
|
|
|
|
src={process.env.NEXT_PUBLIC_WEB_ASSETS_URL + "/images/top_post.png"}
|
|
|
|
|
width={76}
|
|
|
|
|
className="mb-2"
|
|
|
|
|
/>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
)}
|
|
|
|
|
<div className="flex">
|
2024-08-16 13:29:14 +08:00
|
|
|
|
<div
|
|
|
|
|
className="h-max"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
router.push("/profile/" + data.mid);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Image
|
|
|
|
|
className="flex-none w-8 h-8 rounded-full mr-2"
|
|
|
|
|
fit="cover"
|
|
|
|
|
width={"2rem"}
|
|
|
|
|
height={"2rem"}
|
|
|
|
|
src={data.streamer_ext?.avatar.images[0].urls[0]}
|
|
|
|
|
alt=""
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
|
|
|
|
|
<div className="flex-1">
|
2024-08-16 13:29:14 +08:00
|
|
|
|
<div className="flex justify-between items-center ">
|
2024-07-23 20:56:25 +08:00
|
|
|
|
<span className="text-md">{data.streamer_ext?.name}</span>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
{type == "post" && (
|
2024-08-16 13:29:14 +08:00
|
|
|
|
<span
|
|
|
|
|
onClick={() => handleFollow(isFollow, data?.mid, setIsFollow)}
|
|
|
|
|
className="rounded-full bg-[#FFFFFF1A] px-2 py-1 text-xs text-white font-medium"
|
|
|
|
|
>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
{isFollow ? "已关注" : "关注"}
|
2024-06-29 12:07:37 +08:00
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-06-27 18:34:03 +08:00
|
|
|
|
</div>
|
2024-07-31 14:46:03 +08:00
|
|
|
|
{(data?.status === 0 || data?.status === 1) && (
|
|
|
|
|
<div className="flex flex-col items-start mt-2">
|
|
|
|
|
<div className="py-1 px-2 rounded bg-[#3B69B8]">
|
|
|
|
|
<span className="text-white text-sm">审核中</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{data?.status === 3 && (
|
|
|
|
|
<p className="py-1 px-2 inline-block bg-[#F53030] rounded">
|
2024-08-09 22:10:02 +08:00
|
|
|
|
<span className="text-white text-sm">
|
|
|
|
|
审核未通过,请前往APP编辑。
|
|
|
|
|
</span>
|
2024-07-31 14:46:03 +08:00
|
|
|
|
</p>
|
|
|
|
|
)}
|
2024-06-29 12:07:37 +08:00
|
|
|
|
<div>
|
2024-07-17 20:30:33 +08:00
|
|
|
|
{!data?.is_zone_moment_unlocked ? (
|
2024-08-09 22:10:02 +08:00
|
|
|
|
<span
|
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
|
__html: findLinksInText(data.text),
|
|
|
|
|
}}
|
|
|
|
|
className={`mb-2 mt-2 whitespace-pre-wrap ${
|
|
|
|
|
!isOpenText ? "text-ellipsis-7" : ""
|
|
|
|
|
} ${inter.className}`}
|
|
|
|
|
// style={{
|
|
|
|
|
// WebkitLineClamp: data?.text_visible_range < 999?data?.text_visible_range:7,
|
|
|
|
|
// }}
|
|
|
|
|
></span>
|
|
|
|
|
) : (
|
|
|
|
|
<div>
|
|
|
|
|
<span
|
2024-08-05 13:10:33 +08:00
|
|
|
|
className={`mb-2 mt-2 whitespace-pre-wrap ${
|
2024-07-23 20:56:25 +08:00
|
|
|
|
!isOpenText ? "text-ellipsis-7" : ""
|
|
|
|
|
} ${inter.className}`}
|
2024-08-09 22:10:02 +08:00
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
|
__html: findLinksInText(data.text),
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
WebkitLineClamp:
|
|
|
|
|
data?.text_visible_range < 999
|
|
|
|
|
? data?.text_visible_range
|
|
|
|
|
: 7,
|
|
|
|
|
}}
|
|
|
|
|
></span>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-07-18 23:20:42 +08:00
|
|
|
|
{!(
|
|
|
|
|
!data?.is_zone_moment_unlocked && data?.text_visible_range < 999
|
|
|
|
|
) &&
|
|
|
|
|
data.text?.length > 140 && (
|
|
|
|
|
<div
|
|
|
|
|
className="font-bold text-btn my-4 text-base"
|
|
|
|
|
onClick={() => setIsOpenText(!isOpenText)}
|
|
|
|
|
>
|
|
|
|
|
{isOpenText ? "收起" : "全文"}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-06-27 18:34:03 +08:00
|
|
|
|
</div>
|
2024-08-07 21:28:17 +08:00
|
|
|
|
<div className="mr-8 rounded-md">
|
2024-07-15 20:00:44 +08:00
|
|
|
|
{data.media_component && (
|
|
|
|
|
<Photos
|
2024-07-22 19:43:20 +08:00
|
|
|
|
data={data}
|
2024-07-15 20:00:44 +08:00
|
|
|
|
media={data.media_component}
|
|
|
|
|
isUnlocked={data.is_zone_moment_unlocked}
|
|
|
|
|
mediaAmount={data.media_amount}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
mediaVisibleRange={data.media_visible_range}
|
2024-07-19 16:22:43 +08:00
|
|
|
|
type={type}
|
2024-07-15 20:00:44 +08:00
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-07-17 20:30:33 +08:00
|
|
|
|
{type == "space" && !!data.c_type && (
|
2024-07-11 23:57:26 +08:00
|
|
|
|
<PaySpacePost
|
|
|
|
|
type={data.is_ironfan_visible ? "ironFan" : "superFan"}
|
|
|
|
|
price={data.price / 100}
|
|
|
|
|
status={data.is_ironfanship_unlocked}
|
2024-07-31 14:46:03 +08:00
|
|
|
|
is_ironfan_visible={data.is_ironfan_visible == 1}
|
2024-07-11 23:57:26 +08:00
|
|
|
|
ironfanship_price={data.ironfanship_price / 100}
|
|
|
|
|
is_zone_moment_unlocked={data.is_zone_moment_unlocked}
|
|
|
|
|
data={data}
|
2024-07-17 20:30:33 +08:00
|
|
|
|
isCreator={isCreator}
|
2024-07-11 23:57:26 +08:00
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-07-08 20:07:36 +08:00
|
|
|
|
</div>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
<div className="flex justify-between items-center mt-2">
|
|
|
|
|
{type == "post" ? (
|
2024-07-06 11:05:19 +08:00
|
|
|
|
<div
|
|
|
|
|
className="flex items-center"
|
2024-07-17 20:30:33 +08:00
|
|
|
|
onClick={() =>
|
|
|
|
|
router.push("/space/person_space_introduce/" + data.mid)
|
|
|
|
|
}
|
2024-07-06 11:05:19 +08:00
|
|
|
|
>
|
2024-08-02 22:12:54 +08:00
|
|
|
|
{data.streamer_ext.is_active_within_a_week ? (
|
2024-07-03 19:59:39 +08:00
|
|
|
|
<>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
<Image
|
2024-07-31 14:46:03 +08:00
|
|
|
|
src={
|
|
|
|
|
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
|
|
|
|
"/icons/space_new_post.png"
|
|
|
|
|
}
|
2024-07-06 11:05:19 +08:00
|
|
|
|
width={18}
|
|
|
|
|
className="w-4 h-full mr-1"
|
|
|
|
|
placeholder=""
|
|
|
|
|
/>
|
|
|
|
|
<span className="mr-1 text-primary text-xs">
|
2024-08-02 22:12:54 +08:00
|
|
|
|
{/* {data.streamer_ext.days_elapsed_since_the_last_zones_update < 7 &&
|
2024-07-06 11:05:19 +08:00
|
|
|
|
`空间${
|
2024-08-02 22:12:54 +08:00
|
|
|
|
data.streamer_ext.days_elapsed_since_the_last_zones_update === 0
|
2024-07-06 11:05:19 +08:00
|
|
|
|
? "今日"
|
|
|
|
|
: "new" === 1
|
|
|
|
|
? "昨日"
|
|
|
|
|
: "new" === 2
|
|
|
|
|
? "前天"
|
2024-08-02 22:12:54 +08:00
|
|
|
|
: data.streamer_ext.days_elapsed_since_the_last_zones_update +
|
2024-07-06 11:05:19 +08:00
|
|
|
|
"天前"
|
|
|
|
|
}有更新`}
|
2024-08-02 22:12:54 +08:00
|
|
|
|
空间 */}
|
2024-08-09 22:10:02 +08:00
|
|
|
|
空间
|
|
|
|
|
{formatZoneUpdateTime(
|
|
|
|
|
data?.streamer_ext
|
|
|
|
|
?.days_elapsed_since_the_last_zones_update
|
|
|
|
|
)}
|
|
|
|
|
有更新
|
2024-07-06 11:05:19 +08:00
|
|
|
|
</span>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faAngleRight}
|
2024-08-21 11:30:19 +08:00
|
|
|
|
style={{ maxWidth: "12px" }}
|
2024-07-06 11:05:19 +08:00
|
|
|
|
color="#FF669E"
|
|
|
|
|
size="sm"
|
|
|
|
|
/>
|
2024-07-03 19:59:39 +08:00
|
|
|
|
</>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
) : (
|
|
|
|
|
data?.streamer_ext?.zones?.length !== 0 && (
|
|
|
|
|
<div className="text-[#FFFFFFB2] font-medium text-xs flex items-center">
|
|
|
|
|
<span className="mr-1">查看TA的空间</span>
|
2024-08-21 11:30:19 +08:00
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faAngleRight}
|
|
|
|
|
size="sm"
|
|
|
|
|
style={{ maxWidth: "12px" }}
|
|
|
|
|
/>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2024-06-29 12:07:37 +08:00
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="text-[#ffffff88] text-xs">
|
|
|
|
|
<span className="mr-2">
|
|
|
|
|
{getDays < 3
|
|
|
|
|
? `${
|
2024-07-03 19:59:39 +08:00
|
|
|
|
getDays === 0 ? "今日" : "new" === 1 ? "昨日" : "前天"
|
2024-06-29 12:07:37 +08:00
|
|
|
|
}`
|
2024-07-23 20:56:25 +08:00
|
|
|
|
: date.getMonth() + 1 + "-" + date.getDate()}
|
2024-06-29 12:07:37 +08:00
|
|
|
|
</span>
|
2024-07-18 23:20:42 +08:00
|
|
|
|
<span>
|
|
|
|
|
{(date.getHours() > 9
|
|
|
|
|
? date.getHours()
|
|
|
|
|
: "0" + date.getHours()) +
|
|
|
|
|
":" +
|
|
|
|
|
(date.getMinutes() > 9
|
|
|
|
|
? date.getMinutes()
|
|
|
|
|
: "0" + date.getMinutes())}
|
|
|
|
|
</span>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="flex items-center">
|
2024-07-06 11:05:19 +08:00
|
|
|
|
<div
|
|
|
|
|
className="flex items-center mr-4 h-[32px]"
|
2024-07-11 23:57:26 +08:00
|
|
|
|
onClick={() =>
|
|
|
|
|
thumbsUp(data.id, isThumbsUp, setIsThumbsUp, type == "space")
|
|
|
|
|
}
|
2024-07-06 11:05:19 +08:00
|
|
|
|
>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
<Image
|
2024-07-31 14:46:03 +08:00
|
|
|
|
src={
|
|
|
|
|
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
|
2024-07-24 19:08:22 +08:00
|
|
|
|
(isThumbsUp == 1
|
2024-07-06 11:05:19 +08:00
|
|
|
|
? "/icons/thumbup.png"
|
2024-07-24 19:08:22 +08:00
|
|
|
|
: "/icons/notthumbup.png")
|
2024-07-06 11:05:19 +08:00
|
|
|
|
}
|
2024-06-29 12:07:37 +08:00
|
|
|
|
width={32}
|
|
|
|
|
className="w-4 h-full"
|
|
|
|
|
placeholder=""
|
|
|
|
|
/>
|
2024-07-11 23:57:26 +08:00
|
|
|
|
<span
|
|
|
|
|
className={`text-xs ${
|
|
|
|
|
isThumbsUp == 1 ? "text-[#FF669E]" : "text-[#FFFFFF80]"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{isThumbsUp == 1 ? "已赞" : "点赞"}
|
|
|
|
|
</span>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
</div>
|
2024-07-11 23:57:26 +08:00
|
|
|
|
<Popover
|
|
|
|
|
style={{ "--background": "#1E1C29" }}
|
|
|
|
|
content={
|
|
|
|
|
<ul>
|
|
|
|
|
<li
|
|
|
|
|
className="py-1 px-4"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
router.push("/messageDetail");
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
举报
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
}
|
|
|
|
|
trigger="click"
|
|
|
|
|
placement="left"
|
|
|
|
|
>
|
|
|
|
|
<span className="mr-2">···</span>
|
|
|
|
|
</Popover>
|
2024-06-27 18:34:03 +08:00
|
|
|
|
</div>
|
2024-06-25 20:18:37 +08:00
|
|
|
|
</div>
|
2024-06-29 12:07:37 +08:00
|
|
|
|
{/* <div className="rounded-full h-px bg-gray-200 mt-2"></div> */}
|
2024-06-25 20:18:37 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|