"use client"; import React, { useEffect, useRef, useState, useRef } from "react"; import { Tabs, Swiper, Toast, Image, List, InfiniteScroll, SpinLoading, } from "antd-mobile"; import PostItem from "@/components/PostItem"; import "./index.css"; import Link from "next/link"; import Empty from "@/components/Empty"; import { useRouter } from "next/navigation"; import PostItemSkeleton from "@/components/skeletons/PostItemSkeleton"; import require from "@/utils/require"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faRefresh } from "@fortawesome/free-solid-svg-icons"; 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); const [dataList, setDataList] = useState([]); // const [spacePost, setSpacePost] = useState([]); const [hasMore, setHasMore] = useState(true); const [scrollHeight, setScrollHeight] = useState(0); const [offset, setOffset] = useState(0); const [loading, setLoading] = useState(false); const scrollRef = useRef(null); const router = useRouter(); // 获取屏幕高度 // const scrollHeight = 600; useEffect(() => { setScrollHeight(window.innerHeight - 57); // const handleResize = () => { // setScrollHeight(window.innerHeight - 126); // }; // window.addEventListener("resize", handleResize); // return () => { // // window.removeEventListener("resize", handleResize); // }; }, []); useEffect(() => { firstRequest(); }, [activeIndex]); const firstRequest = () => { resetOffset(); if (activeIndex === 0) { getSpaceList(); } if (activeIndex === 1) { getSpacePosts(0).then((res) => { setDataList(res); }); } }; const resetOffset = () => { setOffset(0); // setDataList([]); }; const getSpaceList = async () => { setLoading(true); try { const data = await require("POST", "/api/zone/list_by_visitor_mid"); setLoading(false); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } //在末尾添加元素以展示查看更多卡片 if (data.data.list.length !== 0) { const finalData = [...data.data.list]; setDataList(finalData); return; } } catch (error) { console.error(error); } }; const getSpacePosts = async (offset) => { setLoading(true); try { const data = await require("POST", "/api/zone_moment/list_by_visitor_mid", { body: { offset, limit: 4 }, }); setLoading(false); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } //在末尾添加元素以展示查看更多卡片 if (data.data.list.length !== 0) { const finalData = [...data.data.list]; setOffset(offset + 1); return finalData; } } catch (error) { console.error(error); } }; async function loadMore() { if (!offset) return; const append = await getSpacePosts(offset); if (append) { setDataList((val) => [...val, ...append]); setHasMore(append.length > 0); } } return (
{ const index = tabItems.findIndex((item) => item.key === key); setActiveIndex(index); swiperRef.current?.swipeTo(index); }} > {tabItems.map((item) => ( ))}
null} ref={swiperRef} defaultIndex={activeIndex} onIndexChange={(index) => { setActiveIndex(index); }} > {!activeIndex && (
{!loading ? (
{dataList?.length > 0 ? (
    {dataList?.map((item) => (
  • ))}
  • router.push("/search")}>
    navigation.navigate("Stream")} // onClick={} className="w-full h-52" >
    {/*
    */}

    发现更多

    缘分就在不经意间

    {/* */}
) : (
搜索空间 {/* 查看推荐 */}
)}
) : (
)}
)}
{!!activeIndex && (
{loading && ( <> )} {dataList?.map((item, index) => ( ))} {!dataList?.length && (
)}
)}
{ scrollRef.current?.scrollTo(0, 0); firstRequest(); }} />
); } const VisitingCard = ({ data }) => { const router = useRouter(); return (
router.push("/space/" + data?.streamer_ext?.mid)} > {data?.is_unread_zone_moment_exist === 1 && ( )}
{data?.streamer_ext?.name}
); };