tiefen_space_h5/components/StreamerNavigator/index.js

98 lines
3.3 KiB
JavaScript
Raw Normal View History

2024-08-02 22:12:54 +08:00
"use client";
import React, { useEffect, useState } from "react";
2024-12-20 20:47:20 +08:00
import { Mask, Toast } from "antd-mobile";
2024-12-13 18:24:36 +08:00
import { getStreamer } from "@/api/streamer";
2024-08-02 22:12:54 +08:00
import { useRouter } from "next/navigation";
2024-12-13 18:24:36 +08:00
import { connect } from "react-redux";
import { changeInviter } from "@/store/actions";
2024-12-20 20:47:20 +08:00
import OwnImage from "../OwnImage";
import OwnIcon from "../OwnIcon";
2024-12-13 18:24:36 +08:00
function StreamerNavigator({ userId, changeInviter }) {
const [streamerInfo, setStreamerInfo] = useState(null);
2024-08-02 22:12:54 +08:00
const router = useRouter();
2024-12-13 18:24:36 +08:00
useEffect(() => {
2024-12-20 20:47:20 +08:00
console.log("+++++++", userId);
2024-12-13 18:24:36 +08:00
userId &&
2024-12-20 20:47:20 +08:00
getStreamer(userId)
.then((res) => {
if (!res) {
Toast.show({
content: "此达人不存在",
position: "top",
});
return;
}
setStreamerInfo(res);
})
.catch((eeror) => {});
}, [userId]);
2024-12-13 18:24:36 +08:00
const handleCloseMask = () => {
changeInviter(null);
setStreamerInfo(null);
};
2024-08-02 22:12:54 +08:00
return (
2024-12-13 18:24:36 +08:00
<Mask visible={!!streamerInfo} onMaskClick={handleCloseMask}>
<div className="fixed top-[20%] left-[12.5%] w-3/4 flex-1 justify-center items-center ">
<div className="rounded-2xl bg-[#1E1C29] items-center overflow-hidden">
2024-08-02 22:12:54 +08:00
<div className="flex flex-col w-full">
2024-12-20 20:47:20 +08:00
<OwnImage
2024-08-02 22:12:54 +08:00
src={streamerInfo?.streamer_ext?.cover?.images[0]?.urls[0]}
fit="cover"
2024-12-13 18:24:36 +08:00
style={{ aspectRatio: 1 }}
2024-12-20 20:47:20 +08:00
className="w-full h-full"
2024-08-02 22:12:54 +08:00
/>
<div className="p-4">
<div className="flex flex-row items-center">
2024-12-13 18:24:36 +08:00
<p className="text-xl text-white font-medium mr-1">
2024-08-02 22:12:54 +08:00
{streamerInfo?.streamer_ext?.name}
</p>
2024-12-20 20:47:20 +08:00
<OwnIcon className="w-5 h-5" src="/icons/verification.png" />
2024-08-02 22:12:54 +08:00
</div>
<p className="text-sm text-[#FFFFFFB2] mt-1 truncate ">
2024-12-13 18:24:36 +08:00
{!streamerInfo?.streamer_ext?.zones?.length
? streamerInfo?.streamer_ext?.bio
: streamerInfo?.streamer_ext?.zones[0]?.profile}
2024-08-02 22:12:54 +08:00
</p>
<div
onClick={
streamerInfo?.streamer_ext?.zones?.length === 0
? () => {
handleCloseMask();
2024-12-13 18:24:36 +08:00
router.replace(
"/profile/" + streamerInfo?.streamer_ext?.mid
);
2024-08-02 22:12:54 +08:00
}
: () => {
handleCloseMask();
2024-12-13 18:24:36 +08:00
router.replace(
"/space/person_space_introduce/" +
streamerInfo?.streamer_ext?.mid
);
2024-08-02 22:12:54 +08:00
}
}
className="w-full p-2 mt-4 text-base rounded-full bg-[#FF669E] text-center"
>
2024-12-13 18:24:36 +08:00
{streamerInfo?.streamer_ext?.zones?.length === 0
? "查看主页"
: "查看空间"}
2024-08-02 22:12:54 +08:00
</div>
</div>
</div>
</div>
</div>
</Mask>
);
}
2024-12-13 18:24:36 +08:00
const mapStateToProps = ({ reducer }) => {
return {
userId: parseInt(reducer.inviter, 10),
};
};
const mapDispatchToProps = {
changeInviter,
};
export default connect(mapStateToProps, mapDispatchToProps)(StreamerNavigator);