2024-06-25 20:18:37 +08:00
|
|
|
"use client";
|
|
|
|
|
2024-07-22 16:07:41 +08:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
2024-07-15 16:54:04 +08:00
|
|
|
import {
|
|
|
|
Tabs,
|
|
|
|
Swiper,
|
|
|
|
Toast,
|
|
|
|
Image,
|
|
|
|
List,
|
|
|
|
InfiniteScroll,
|
|
|
|
SpinLoading,
|
|
|
|
} from "antd-mobile";
|
2024-06-25 20:18:37 +08:00
|
|
|
import PostItem from "@/components/PostItem";
|
|
|
|
import "./index.css";
|
|
|
|
import Link from "next/link";
|
|
|
|
import Empty from "@/components/Empty";
|
2024-06-29 12:07:37 +08:00
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
import PostItemSkeleton from "@/components/skeletons/PostItemSkeleton";
|
2024-07-22 16:07:41 +08:00
|
|
|
import requireAPI from "@/utils/requireAPI";
|
2024-07-06 16:03:15 +08:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { faRefresh } from "@fortawesome/free-solid-svg-icons";
|
2024-06-25 20:18:37 +08:00
|
|
|
const tabItems = [
|
|
|
|
{ key: "space", title: "空间" },
|
|
|
|
{ key: "post", title: "动态" },
|
|
|
|
];
|
|
|
|
// const scrollHeight = 700;
|
|
|
|
// const scrollHeight = window.innerHeight-126
|
|
|
|
export default function Space() {
|
|
|
|
const swiperRef = useRef(null);
|
|
|
|
const [activeIndex, setActiveIndex] = useState(0);
|
2024-07-15 16:54:04 +08:00
|
|
|
const [dataList, setDataList] = useState([]);
|
2024-07-06 16:03:15 +08:00
|
|
|
// const [spacePost, setSpacePost] = useState([]);
|
2024-06-25 20:18:37 +08:00
|
|
|
const [hasMore, setHasMore] = useState(true);
|
|
|
|
const [scrollHeight, setScrollHeight] = useState(0);
|
2024-07-06 16:03:15 +08:00
|
|
|
const [offset, setOffset] = useState(0);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const scrollRef = useRef(null);
|
2024-07-10 16:50:53 +08:00
|
|
|
const router = useRouter();
|
2024-06-25 20:18:37 +08:00
|
|
|
// 获取屏幕高度
|
|
|
|
// const scrollHeight = 600;
|
|
|
|
useEffect(() => {
|
2024-07-08 20:07:36 +08:00
|
|
|
setScrollHeight(window.innerHeight - 57);
|
2024-06-25 20:18:37 +08:00
|
|
|
// const handleResize = () => {
|
|
|
|
// setScrollHeight(window.innerHeight - 126);
|
|
|
|
// };
|
|
|
|
// window.addEventListener("resize", handleResize);
|
|
|
|
// return () => {
|
|
|
|
// // window.removeEventListener("resize", handleResize);
|
|
|
|
// };
|
|
|
|
}, []);
|
2024-07-06 16:03:15 +08:00
|
|
|
useEffect(() => {
|
2024-07-10 16:50:53 +08:00
|
|
|
firstRequest();
|
2024-07-06 16:03:15 +08:00
|
|
|
}, [activeIndex]);
|
|
|
|
const firstRequest = () => {
|
|
|
|
resetOffset();
|
|
|
|
if (activeIndex === 0) {
|
|
|
|
getSpaceList();
|
|
|
|
}
|
|
|
|
if (activeIndex === 1) {
|
|
|
|
getSpacePosts(0).then((res) => {
|
|
|
|
setDataList(res);
|
|
|
|
});
|
2024-06-25 20:18:37 +08:00
|
|
|
}
|
2024-07-10 16:50:53 +08:00
|
|
|
};
|
2024-07-06 16:03:15 +08:00
|
|
|
const resetOffset = () => {
|
|
|
|
setOffset(0);
|
|
|
|
// setDataList([]);
|
|
|
|
};
|
|
|
|
const getSpaceList = async () => {
|
|
|
|
setLoading(true);
|
|
|
|
try {
|
2024-07-22 16:07:41 +08:00
|
|
|
const data = await requireAPI("POST", "/api/zone/list_by_visitor_mid");
|
2024-07-06 16:03:15 +08:00
|
|
|
setLoading(false);
|
|
|
|
if (data.ret === -1) {
|
|
|
|
Toast.show({
|
2024-07-08 20:07:36 +08:00
|
|
|
icon: "fail",
|
|
|
|
content: data.msg,
|
|
|
|
position: "top",
|
2024-07-06 16:03:15 +08:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//在末尾添加元素以展示查看更多卡片
|
|
|
|
if (data.data.list.length !== 0) {
|
2024-07-10 16:50:53 +08:00
|
|
|
const finalData = [...data.data.list];
|
2024-07-06 16:03:15 +08:00
|
|
|
setDataList(finalData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const getSpacePosts = async (offset) => {
|
|
|
|
setLoading(true);
|
|
|
|
try {
|
|
|
|
const data =
|
2024-07-22 16:07:41 +08:00
|
|
|
await requireAPI("POST", "/api/zone_moment/list_by_visitor_mid", {
|
2024-07-06 16:03:15 +08:00
|
|
|
body: { offset, limit: 4 },
|
|
|
|
});
|
|
|
|
setLoading(false);
|
|
|
|
if (data.ret === -1) {
|
|
|
|
Toast.show({
|
2024-07-08 20:07:36 +08:00
|
|
|
icon: "fail",
|
|
|
|
content: data.msg,
|
|
|
|
position: "top",
|
2024-07-06 16:03:15 +08:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//在末尾添加元素以展示查看更多卡片
|
|
|
|
if (data.data.list.length !== 0) {
|
|
|
|
const finalData = [...data.data.list];
|
|
|
|
setOffset(offset + 1);
|
|
|
|
return finalData;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
};
|
2024-06-25 20:18:37 +08:00
|
|
|
async function loadMore() {
|
2024-07-06 16:03:15 +08:00
|
|
|
if (!offset) return;
|
|
|
|
const append = await getSpacePosts(offset);
|
2024-07-10 16:50:53 +08:00
|
|
|
if (append) {
|
2024-07-08 20:07:36 +08:00
|
|
|
setDataList((val) => [...val, ...append]);
|
|
|
|
setHasMore(append.length > 0);
|
|
|
|
}
|
2024-06-25 20:18:37 +08:00
|
|
|
}
|
|
|
|
return (
|
2024-07-10 16:50:53 +08:00
|
|
|
<div
|
|
|
|
className="h-screen overflow-x-hidden"
|
|
|
|
style={{ maxHeight: `${scrollHeight}px` }}
|
|
|
|
>
|
2024-07-08 20:07:36 +08:00
|
|
|
<div className="flex justify-between items-center px-2 custom-tabs text-gray-400 sticky top-0 z-10 bg-deepBg">
|
2024-06-25 20:18:37 +08:00
|
|
|
<Tabs
|
|
|
|
activeKey={tabItems[activeIndex].key}
|
|
|
|
onChange={(key) => {
|
|
|
|
const index = tabItems.findIndex((item) => item.key === key);
|
|
|
|
setActiveIndex(index);
|
|
|
|
swiperRef.current?.swipeTo(index);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{tabItems.map((item) => (
|
|
|
|
<Tabs.Tab
|
|
|
|
forceRender={false}
|
|
|
|
title={item.title}
|
|
|
|
key={item.key}
|
|
|
|
className="text-left"
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Tabs>
|
2024-06-29 12:07:37 +08:00
|
|
|
<Link
|
|
|
|
href="search"
|
|
|
|
className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full"
|
|
|
|
>
|
|
|
|
<Image src="/icons/search.png" />
|
|
|
|
</Link>
|
2024-06-25 20:18:37 +08:00
|
|
|
</div>
|
|
|
|
<Swiper
|
|
|
|
direction="horizontal"
|
|
|
|
indicator={() => null}
|
|
|
|
ref={swiperRef}
|
|
|
|
defaultIndex={activeIndex}
|
|
|
|
onIndexChange={(index) => {
|
|
|
|
setActiveIndex(index);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Swiper.Item>
|
2024-07-06 16:03:15 +08:00
|
|
|
{!activeIndex && (
|
2024-07-15 16:54:04 +08:00
|
|
|
<div>
|
2024-07-15 20:00:44 +08:00
|
|
|
{!loading ? (
|
|
|
|
<div className="px-4 pb-8">
|
2024-07-17 16:58:27 +08:00
|
|
|
{dataList?.length > 0 ? (
|
2024-07-15 20:00:44 +08:00
|
|
|
<ul className="grid grid-cols-2 gap-2 overflow-y-auto">
|
|
|
|
{dataList?.map((item) => (
|
|
|
|
<li key={item.id}>
|
|
|
|
<VisitingCard data={item} />
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
<li onClick={() => router.push("/search")}>
|
|
|
|
<div
|
|
|
|
// onPress={() => navigation.navigate("Stream")}
|
|
|
|
// onClick={}
|
|
|
|
className="w-full h-52"
|
|
|
|
>
|
|
|
|
<div className="h-full flex flex-col rounded-lg overflow-hidden bg-[#FFFFFF1A]">
|
|
|
|
{/* <div className="w-full z-0"></div>
|
2024-07-15 16:54:04 +08:00
|
|
|
<div
|
|
|
|
className="w-full z-0 h-[42px]"
|
|
|
|
></div> */}
|
2024-07-15 20:00:44 +08:00
|
|
|
<div className="flex flex-col w-full h-full px-[22px] py-[30px]">
|
|
|
|
<p className="text-white font-medium text-lg">
|
|
|
|
发现更多
|
|
|
|
</p>
|
|
|
|
<p className="text-[#FFFFFF40] font-sm">
|
|
|
|
缘分就在不经意间
|
|
|
|
</p>
|
|
|
|
<Image
|
|
|
|
width={32}
|
|
|
|
height={32}
|
|
|
|
className="mt-4"
|
|
|
|
src="/icons/rightarrow_border.png"
|
|
|
|
/>
|
|
|
|
{/* <Image
|
2024-07-15 16:54:04 +08:00
|
|
|
width={32}
|
|
|
|
height={32}
|
|
|
|
className="absolute bottom-0 right-0"
|
|
|
|
src="/icons/magnifier.png"
|
2024-07-15 20:00:44 +08:00
|
|
|
/> */}
|
|
|
|
</div>
|
2024-07-15 16:54:04 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-07-15 20:00:44 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className={`flex flex-col items-center justify-center`}
|
|
|
|
style={{ height: `${scrollHeight}px` }}
|
|
|
|
>
|
|
|
|
<Empty type="nospace" />
|
|
|
|
<div className="flex flex-col mt-6">
|
|
|
|
<Link
|
|
|
|
href="/search"
|
|
|
|
className="bg-[#FFFFFF40] px-12 py-2 rounded-full text-base text-white"
|
|
|
|
>
|
|
|
|
搜索空间
|
|
|
|
</Link>
|
2024-07-16 20:20:12 +08:00
|
|
|
{/* <Link
|
2024-07-15 20:00:44 +08:00
|
|
|
href="/search"
|
|
|
|
className="bg-[#FFFFFF40] px-12 py-2 rounded-full text-base text-white mt-2"
|
|
|
|
>
|
|
|
|
查看推荐
|
2024-07-16 20:20:12 +08:00
|
|
|
</Link> */}
|
2024-07-10 16:50:53 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-07-15 20:00:44 +08:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
2024-07-06 16:03:15 +08:00
|
|
|
<div
|
2024-07-15 16:54:04 +08:00
|
|
|
className="w-full text-center flex items-center justify-center"
|
|
|
|
style={{ height: scrollHeight - 60 + "px" }}
|
2024-07-06 16:03:15 +08:00
|
|
|
>
|
2024-07-15 16:54:04 +08:00
|
|
|
<SpinLoading />
|
2024-07-06 16:03:15 +08:00
|
|
|
</div>
|
|
|
|
)}
|
2024-07-15 16:54:04 +08:00
|
|
|
</div>
|
2024-07-06 16:03:15 +08:00
|
|
|
)}
|
2024-06-25 20:18:37 +08:00
|
|
|
</Swiper.Item>
|
|
|
|
<Swiper.Item>
|
2024-07-10 16:50:53 +08:00
|
|
|
{!!activeIndex && (
|
|
|
|
<div className="px-4 pb-8" ref={scrollRef}>
|
|
|
|
<List className="scrollbarBox_hidden">
|
2024-07-06 16:03:15 +08:00
|
|
|
{loading && (
|
|
|
|
<>
|
|
|
|
<PostItemSkeleton />
|
|
|
|
<PostItemSkeleton />
|
|
|
|
<PostItemSkeleton />
|
|
|
|
<PostItemSkeleton />
|
|
|
|
</>
|
|
|
|
)}
|
2024-07-15 16:54:04 +08:00
|
|
|
{dataList?.map((item, index) => (
|
2024-07-10 16:50:53 +08:00
|
|
|
<List.Item className="!p-0" key={item.id + "_" + index}>
|
2024-07-15 16:54:04 +08:00
|
|
|
<PostItem
|
|
|
|
type="space"
|
|
|
|
data={item}
|
|
|
|
date={new Date(item.ct * 1000)}
|
|
|
|
/>
|
2024-07-10 16:50:53 +08:00
|
|
|
</List.Item>
|
|
|
|
))}
|
2024-07-06 16:03:15 +08:00
|
|
|
<InfiniteScroll loadMore={loadMore} hasMore={hasMore} />
|
|
|
|
</List>
|
2024-07-17 16:58:27 +08:00
|
|
|
{!dataList?.length && (
|
2024-07-06 16:03:15 +08:00
|
|
|
<div
|
|
|
|
className={`flex flex-col items-center justify-center`}
|
|
|
|
style={{ height: `${scrollHeight}px` }}
|
|
|
|
>
|
|
|
|
<Empty type="nodata" />
|
|
|
|
</div>
|
|
|
|
)}
|
2024-06-29 12:07:37 +08:00
|
|
|
</div>
|
2024-07-10 16:50:53 +08:00
|
|
|
)}
|
2024-06-25 20:18:37 +08:00
|
|
|
</Swiper.Item>
|
|
|
|
</Swiper>
|
2024-07-06 16:03:15 +08:00
|
|
|
<div
|
2024-07-15 16:54:04 +08:00
|
|
|
className={`fixed bottom-[96px] right-4 z-[999] w-10 h-10 flex items-center justify-center bg-[#1d1d1d71] rounded-full text-white ${
|
2024-07-10 16:50:53 +08:00
|
|
|
loading && !offset ? "animate-spin" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faRefresh}
|
|
|
|
size="xl"
|
|
|
|
// onClick={firstRequest}
|
|
|
|
onClick={() => {
|
|
|
|
scrollRef.current?.scrollTo(0, 0);
|
|
|
|
firstRequest();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-07-06 11:05:19 +08:00
|
|
|
</div>
|
2024-06-25 20:18:37 +08:00
|
|
|
);
|
|
|
|
}
|
2024-06-29 12:07:37 +08:00
|
|
|
|
2024-07-06 16:03:15 +08:00
|
|
|
const VisitingCard = ({ data }) => {
|
2024-06-29 12:07:37 +08:00
|
|
|
const router = useRouter();
|
|
|
|
return (
|
|
|
|
<div
|
2024-07-10 16:50:53 +08:00
|
|
|
className="relative h-52"
|
2024-07-06 16:03:15 +08:00
|
|
|
onClick={() => router.push("/space/" + data?.streamer_ext?.mid)}
|
2024-06-29 12:07:37 +08:00
|
|
|
>
|
2024-07-06 16:03:15 +08:00
|
|
|
{data?.is_unread_zone_moment_exist === 1 && (
|
|
|
|
<Image
|
|
|
|
src="/images/space_new.png"
|
|
|
|
width={78}
|
|
|
|
fit="contain"
|
|
|
|
className="absolute top-2 right-2"
|
|
|
|
/>
|
|
|
|
)}
|
2024-06-29 12:07:37 +08:00
|
|
|
<Image
|
|
|
|
width={"100%"}
|
|
|
|
height={"100%"}
|
2024-07-06 16:03:15 +08:00
|
|
|
src={data?.streamer_ext?.cover.images[0].urls[0]}
|
|
|
|
fit="cover"
|
2024-06-29 12:07:37 +08:00
|
|
|
className="rounded-lg"
|
|
|
|
/>
|
|
|
|
<div className="absolute bottom-0 left-0 w-full px-2 py-3 bg-[#1b1b1b] flex items-center rounded-b-lg">
|
2024-07-15 16:54:04 +08:00
|
|
|
<span className="font-bold overflow-hidden whitespace-nowrap text-ellipsis">
|
|
|
|
{data?.streamer_ext?.name}
|
|
|
|
</span>
|
2024-07-15 20:00:44 +08:00
|
|
|
<ul className="flex ml-2">
|
|
|
|
{data.visitor_role === 3 && (
|
2024-07-15 16:54:04 +08:00
|
|
|
<li className="text-[10px] bg-primary rounded px-1 mr-1 whitespace-nowrap">
|
2024-07-15 20:00:44 +08:00
|
|
|
创建者
|
2024-07-15 16:54:04 +08:00
|
|
|
</li>
|
2024-07-06 16:03:15 +08:00
|
|
|
)}
|
2024-07-15 20:00:44 +08:00
|
|
|
{data?.admission_price !== 0 && (
|
2024-07-15 16:54:04 +08:00
|
|
|
<li className="text-[10px] bg-primary rounded px-1 mr-1 whitespace-nowrap">
|
|
|
|
付费
|
|
|
|
</li>
|
2024-07-06 16:03:15 +08:00
|
|
|
)}
|
2024-06-29 12:07:37 +08:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|