2024-01-25 03:43:07 +08:00
|
|
|
import {
|
|
|
|
View,
|
|
|
|
RefreshControl,
|
|
|
|
ActivityIndicator,
|
|
|
|
Image as NativeImage,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
|
|
|
} from "react-native";
|
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
import Empty from "../../../components/Empty";
|
|
|
|
import { useTailwind } from "tailwind-rn";
|
|
|
|
import baseRequest from "../../../utils/baseRequest";
|
|
|
|
import Toast from "react-native-toast-message";
|
|
|
|
import { generateSignature } from "../../../utils/crypto";
|
|
|
|
import { FlashList } from "@shopify/flash-list";
|
|
|
|
import Post from "../../../components/Post";
|
|
|
|
import { useNavigation } from "@react-navigation/native";
|
|
|
|
|
|
|
|
export default function FeedPosts({ blur }) {
|
|
|
|
const navigation = useNavigation();
|
|
|
|
//获取当前时间
|
|
|
|
const [currentTime, setCurrentTime] = useState();
|
|
|
|
const getCurrentTime = async () => {
|
|
|
|
setCurrentTime(Math.floor(new Date().getTime() / 1000));
|
|
|
|
};
|
|
|
|
|
|
|
|
//获取截止当前时间的动态数据
|
|
|
|
const [data, setData] = useState([]);
|
|
|
|
const [offset, setOffset] = useState(0);
|
|
|
|
const [more, setMore] = useState(1);
|
|
|
|
const [isActivityIndicatorShow, setIsActivityIndicatorShow] = useState(true);
|
|
|
|
const getData = async (type) => {
|
|
|
|
if (!currentTime) return;
|
|
|
|
if (data.length === 0 && type === "bottom") return;
|
|
|
|
if (!more && type === "bottom") {
|
|
|
|
setIsActivityIndicatorShow(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setIsActivityIndicatorShow(true);
|
|
|
|
try {
|
|
|
|
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
|
|
const base = await baseRequest();
|
|
|
|
const signature = await generateSignature({
|
|
|
|
ct_upper_bound: currentTime,
|
|
|
|
offset: offset,
|
|
|
|
limit: 4,
|
|
|
|
...base,
|
|
|
|
});
|
|
|
|
const _response = await fetch(
|
|
|
|
`${apiUrl}/api/moment/list?signature=${signature}`,
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
ct_upper_bound: currentTime,
|
|
|
|
offset: offset,
|
|
|
|
limit: 4,
|
|
|
|
...base,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const _data = await _response.json();
|
|
|
|
if (_data.ret === -1) {
|
|
|
|
Toast.show({
|
|
|
|
type: "error",
|
|
|
|
text1: _data.msg,
|
|
|
|
topOffset: 60,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (type === "top") {
|
|
|
|
setData((prev) => _data.data.list);
|
|
|
|
} else {
|
|
|
|
setData((prev) => [...prev, ..._data.data.list]);
|
|
|
|
}
|
|
|
|
setOffset(_data.data.offset);
|
|
|
|
setMore(_data.data.more);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//获取当前时间
|
|
|
|
useEffect(() => {
|
|
|
|
getCurrentTime();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
//当时间改变,获取新数据
|
|
|
|
useEffect(() => {
|
|
|
|
getData("top");
|
|
|
|
}, [currentTime]);
|
|
|
|
|
|
|
|
const tailwind = useTailwind();
|
|
|
|
const renderItem = ({ item }) => <Post blur={blur} data={item} />;
|
|
|
|
const [refreshing, setRefreshing] = useState(false);
|
|
|
|
//下拉刷新
|
|
|
|
const handleRefresh = async () => {
|
|
|
|
setRefreshing(true);
|
|
|
|
setOffset(0);
|
|
|
|
setMore(1);
|
|
|
|
await getCurrentTime();
|
|
|
|
setRefreshing(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={tailwind("flex-1")}>
|
|
|
|
<FlashList
|
|
|
|
data={data}
|
|
|
|
renderItem={renderItem}
|
|
|
|
estimatedItemSize={310}
|
|
|
|
initialNumToRender={4}
|
|
|
|
refreshControl={
|
|
|
|
<RefreshControl
|
|
|
|
colors={["#FF669E"]}
|
|
|
|
tintColor="white"
|
|
|
|
refreshing={refreshing}
|
|
|
|
onRefresh={() => handleRefresh()}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
onEndReached={() => getData("bottom")}
|
|
|
|
ListEmptyComponent={<Empty type="nodata" />}
|
|
|
|
ListFooterComponent={
|
|
|
|
<View>
|
|
|
|
{isActivityIndicatorShow && data.length !== 0 && (
|
|
|
|
<ActivityIndicator style={tailwind("my-4")} size="large" />
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
}
|
|
|
|
keyExtractor={(item) => item.id}
|
|
|
|
/>
|
|
|
|
{blur && (
|
|
|
|
<View
|
|
|
|
style={tailwind(
|
|
|
|
"flex flex-row items-center justify-between h-12 bg-[#301024] px-4"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<View style={tailwind("flex flex-row items-center")}>
|
|
|
|
<NativeImage
|
|
|
|
source={require("../../../assets/icon/others/vipbig.png")}
|
|
|
|
/>
|
|
|
|
<Text style={tailwind("text-[#FF669E] text-base font-medium ml-1")}>
|
2024-01-28 23:30:29 +08:00
|
|
|
开通会员订阅动态
|
2024-01-25 03:43:07 +08:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() =>
|
|
|
|
navigation.navigate("WebWithoutHeader", {
|
|
|
|
uri: process.env.EXPO_PUBLIC_WEB_URL + "/vip",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
style={tailwind(
|
|
|
|
"flex justify-center items-center h-9 bg-[#FF669E] rounded-full px-4"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Text style={tailwind("text-white text-sm font-medium")}>
|
2024-01-28 23:30:29 +08:00
|
|
|
¥99/永久
|
2024-01-25 03:43:07 +08:00
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|