tiefen_space_h5/components/PostItem/index.js

167 lines
6.1 KiB
JavaScript
Raw Normal View History

2024-06-25 20:18:37 +08:00
"use client";
2024-06-29 12:07:37 +08:00
import React, { useEffect, useState, useMemo } 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";
import { Image } 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";
import {get} from "@/utils/storeInfo"
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();
const [isOpenText, setIsOpenText] = useState(false);
2024-07-06 11:05:19 +08:00
const [isFollow, setIsFollow] = useState(data.is_followed);
2024-07-08 20:07:36 +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);
useEffect(() => {
2024-07-06 11:05:19 +08:00
const account = get("account");
if (account.mid === data.mid) setIsCreator(true);
return () => {
2024-07-06 11:05:19 +08:00
router.prefetch("/profile/"+data.mid);
};
}, []);
2024-06-29 12:07:37 +08:00
const getDays = useMemo(() => {
const today = new Date();
const days = Math.floor((today - date) / (1000 * 60 * 60 * 24));
return days;
}, []);
2024-06-25 20:18:37 +08:00
return (
2024-06-29 12:07:37 +08:00
<div>
2024-07-08 20:07:36 +08:00
{type == "space" && data?.is_headed === 1 && (
2024-06-29 12:07:37 +08:00
<Image src="/images/top_post.png" width={76} className="mb-2" />
)}
<div className="flex">
<img
className="flex-none w-8 h-8 rounded-full mr-2"
2024-07-03 19:59:39 +08:00
src={data.streamer_ext?.avatar.images[0].urls[0]}
2024-06-29 12:07:37 +08:00
alt=""
2024-07-06 11:05:19 +08:00
onClick={() => router.push("/profile/"+data.mid)}
/>
2024-06-29 12:07:37 +08:00
<div className="flex-1">
2024-07-06 11:05:19 +08:00
<div
className="flex justify-between items-center"
onClick={() => handleFollow(isFollow, data?.mid, setIsFollow)}
>
2024-07-03 19:59:39 +08:00
<span className="font-bold text-md">{data.streamer_ext?.name}</span>
2024-06-29 12:07:37 +08:00
{type == "post" && (
<span 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>
)}
</div>
2024-06-29 12:07:37 +08:00
<div>
<p className={`mb-2 mt-2 ${!isOpenText ? "text-ellipsis-3" : ""}`}>
2024-07-03 19:59:39 +08:00
{data.text}
2024-06-29 12:07:37 +08:00
</p>
2024-07-06 11:05:19 +08:00
{data.text?.length > 50 && (
2024-07-03 19:59:39 +08:00
<div
2024-07-06 11:05:19 +08:00
className="font-bold text-btn my-4 text-base"
onClick={() => setIsOpenText(!isOpenText)}
>
{isOpenText ? "收起" : "全文"}
</div>
)}
</div>
2024-07-08 20:07:36 +08:00
<div className="mr-8">
2024-07-03 19:59:39 +08:00
{data.media_component && <Photos media={data.media_component} />}
2024-07-06 11:05:19 +08:00
{type == "space" && !isCreator && !!data.c_type && (
<PaySpacePost
type={data.is_ironfan_visible ? "ironFan" : "superFan"}
price={data.price / 100}
status={data.is_ironfanship_unlocked}
ironfanship_price={data.ironfanship_price / 100}
is_zone_moment_unlocked={data.is_zone_moment_unlocked}
data={data}
/>
2024-06-29 12:07:37 +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"
onClick={() => router.push("/profile/"+data.mid)}
>
{data.is_active_within_a_week ? (
2024-07-03 19:59:39 +08:00
<>
2024-07-06 11:05:19 +08:00
<Image
src="/icons/space_new_post.png"
width={18}
className="w-4 h-full mr-1"
placeholder=""
/>
<span className="mr-1 text-primary text-xs">
{data.days_elapsed_since_the_last_zones_update < 7 &&
`空间${
data.days_elapsed_since_the_last_zones_update === 0
? "今日"
: "new" === 1
? "昨日"
: "new" === 2
? "前天"
: data.days_elapsed_since_the_last_zones_update +
"天前"
}有更新`}
</span>
<FontAwesomeIcon
icon={faAngleRight}
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>
<FontAwesomeIcon icon={faAngleRight} size="sm" />
</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-03 19:59:39 +08:00
: date.getMonth() + 1 + "月" + date.getDate() + "日"}
2024-06-29 12:07:37 +08:00
</span>
2024-07-03 19:59:39 +08:00
<span>{date.getHours() + ":" + 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-08 20:07:36 +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-06 11:05:19 +08:00
src={
isThumbsUp == 1
? "/icons/thumbup.png"
: "/icons/notthumbup.png"
}
2024-06-29 12:07:37 +08:00
width={32}
className="w-4 h-full"
placeholder=""
/>
<span className="text-xs">点赞</span>
</div>
<span className="mr-2">···</span>
</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>
);
}