2024-01-10 01:17:58 +08:00
|
|
|
|
import { View, RefreshControl } from "react-native";
|
|
|
|
|
import React, { useState, useEffect } from "react";
|
2023-12-29 00:27:44 +08:00
|
|
|
|
import StreamerCard from "../../../components/StreamerCard";
|
|
|
|
|
import Empty from "../../../components/Empty";
|
|
|
|
|
import { useTailwind } from "tailwind-rn";
|
|
|
|
|
import baseRequest from "../../../utils/baseRequest";
|
|
|
|
|
import Toast from "react-native-toast-message";
|
|
|
|
|
import { get } from "../../../utils/storeInfo";
|
|
|
|
|
import { generateSignature } from "../../../utils/crypto";
|
|
|
|
|
import { FlashList } from "@shopify/flash-list";
|
|
|
|
|
|
|
|
|
|
export default function FollowStream() {
|
|
|
|
|
//获取关注的主播mid
|
|
|
|
|
const [followMids, setFollowMids] = useState([]);
|
|
|
|
|
const getFollowMids = async () => {
|
|
|
|
|
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
|
|
|
try {
|
|
|
|
|
const base = await baseRequest();
|
|
|
|
|
const account = await get("account");
|
|
|
|
|
const signature = await generateSignature({
|
|
|
|
|
mid: account.mid,
|
2024-01-08 02:11:42 +08:00
|
|
|
|
offset: 0,
|
|
|
|
|
limit: 100,
|
2023-12-29 00:27:44 +08:00
|
|
|
|
...base,
|
|
|
|
|
});
|
|
|
|
|
//查关注mid
|
|
|
|
|
const response = await fetch(
|
|
|
|
|
`${apiUrl}/api/account_relation/list_follow?signature=${signature}`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
mid: account.mid,
|
2024-01-08 02:11:42 +08:00
|
|
|
|
offset: 0,
|
|
|
|
|
limit: 100,
|
2023-12-29 00:27:44 +08:00
|
|
|
|
...base,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const temData = await response.json();
|
|
|
|
|
if (temData.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
type: "error",
|
|
|
|
|
text1: temData.msg,
|
|
|
|
|
topOffset: 60,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const temFollowsMids = temData.data.list.map((item) => item.obj_mid);
|
|
|
|
|
setFollowMids(temFollowsMids);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//获取主播详细数据
|
|
|
|
|
const [data, setData] = useState([]);
|
|
|
|
|
const [offset, setOffset] = useState(0);
|
|
|
|
|
const [more, setMore] = useState(1);
|
|
|
|
|
const getData = async (type) => {
|
2024-01-16 22:45:39 +08:00
|
|
|
|
if (followMids.length === 0) {
|
|
|
|
|
setData((prev) => []);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (data.length === 0 && type === "bottom") return;
|
2023-12-29 00:27:44 +08:00
|
|
|
|
if (!more) return;
|
|
|
|
|
try {
|
|
|
|
|
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
|
|
|
const base = await baseRequest();
|
|
|
|
|
const signature = await generateSignature({
|
|
|
|
|
mids: followMids,
|
|
|
|
|
offset: offset,
|
2024-01-08 02:11:42 +08:00
|
|
|
|
limit: 4,
|
2023-12-29 00:27:44 +08:00
|
|
|
|
...base,
|
|
|
|
|
});
|
|
|
|
|
//查关注主播展示资料
|
|
|
|
|
const followsResponse = await fetch(
|
|
|
|
|
`${apiUrl}/api/streamer/list_ext_by_mids?signature=${signature}`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
mids: followMids,
|
|
|
|
|
offset: offset,
|
2024-01-08 02:11:42 +08:00
|
|
|
|
limit: 4,
|
2023-12-29 00:27:44 +08:00
|
|
|
|
...base,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const followsData = await followsResponse.json();
|
|
|
|
|
if (followsData.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
type: "error",
|
|
|
|
|
text1: followsData.msg,
|
|
|
|
|
topOffset: 60,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (type === "top") {
|
|
|
|
|
setData((prev) => followsData.data.list);
|
|
|
|
|
} else {
|
|
|
|
|
setData((prev) => [...prev, ...followsData.data.list]);
|
|
|
|
|
}
|
|
|
|
|
setOffset(followsData.data.offset);
|
|
|
|
|
setMore(followsData.data.more);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//获取关注的主播mids
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getFollowMids();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
//当关注的主播mids改变,获取新数据
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getData("top");
|
|
|
|
|
}, [followMids]);
|
|
|
|
|
|
|
|
|
|
const tailwind = useTailwind();
|
2024-01-10 01:17:58 +08:00
|
|
|
|
const renderItem = ({ item }) => <StreamerCard data={item} />;
|
2023-12-29 00:27:44 +08:00
|
|
|
|
const [refreshing, setRefreshing] = useState(false);
|
|
|
|
|
//下拉刷新
|
|
|
|
|
const handleRefresh = async () => {
|
|
|
|
|
setRefreshing(true);
|
|
|
|
|
setOffset(0);
|
|
|
|
|
setMore(1);
|
|
|
|
|
await getFollowMids();
|
|
|
|
|
setRefreshing(false);
|
|
|
|
|
};
|
2024-01-10 01:17:58 +08:00
|
|
|
|
|
2023-12-29 00:27:44 +08:00
|
|
|
|
return (
|
2024-01-10 01:17:58 +08:00
|
|
|
|
<View style={tailwind("flex-1")}>
|
|
|
|
|
<FlashList
|
|
|
|
|
data={data}
|
|
|
|
|
renderItem={renderItem}
|
2024-01-16 22:45:39 +08:00
|
|
|
|
estimatedItemSize={287}
|
2024-01-10 01:17:58 +08:00
|
|
|
|
initialNumToRender={4}
|
|
|
|
|
refreshControl={
|
|
|
|
|
<RefreshControl
|
|
|
|
|
colors={["#FF669E"]}
|
|
|
|
|
tintColor="white"
|
|
|
|
|
refreshing={refreshing}
|
|
|
|
|
onRefresh={() => handleRefresh()}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
onEndReached={() => getData("bottom")}
|
|
|
|
|
ListEmptyComponent={<Empty type="friendship" />}
|
|
|
|
|
keyExtractor={(item) => item.mid}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
2023-12-29 00:27:44 +08:00
|
|
|
|
);
|
|
|
|
|
}
|