1
This commit is contained in:
@@ -22,6 +22,7 @@ interface FollowItem {
|
||||
const NewFollow = () => {
|
||||
const [followList, setFollowList] = useState<FollowItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
getFollowList();
|
||||
@@ -69,10 +70,15 @@ const NewFollow = () => {
|
||||
const date = new Date(timeStr);
|
||||
const now = new Date();
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const minutes = Math.floor(diff / (1000 * 60));
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (hours < 24) {
|
||||
if (minutes < 1) {
|
||||
return "刚刚";
|
||||
} else if (minutes < 60) {
|
||||
return `${minutes}分钟前`;
|
||||
} else if (hours < 24) {
|
||||
return `${hours}小时前`;
|
||||
} else if (days === 1) {
|
||||
return "1天前";
|
||||
@@ -85,33 +91,49 @@ const NewFollow = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 处理回关
|
||||
// 处理回关/取消关注
|
||||
const handleFollowBack = async (item: FollowItem) => {
|
||||
if (item.is_mutual) {
|
||||
// 已经互相关注,无需操作
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await FollowService.follow_back(item.user_id);
|
||||
|
||||
Taro.showToast({
|
||||
title: "关注成功",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
// 更新列表
|
||||
setFollowList(prevList =>
|
||||
prevList.map(followItem =>
|
||||
followItem.id === item.id
|
||||
? { ...followItem, is_mutual: true }
|
||||
: followItem
|
||||
)
|
||||
);
|
||||
if (item.is_mutual) {
|
||||
// 已经互相关注,点击取消关注
|
||||
await FollowService.unfollow_user(item.user_id);
|
||||
|
||||
Taro.showToast({
|
||||
title: "取消关注成功",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
// 更新列表
|
||||
setFollowList(prevList =>
|
||||
prevList.map(followItem =>
|
||||
followItem.id === item.id
|
||||
? { ...followItem, is_mutual: false }
|
||||
: followItem
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// 未互关,点击回关
|
||||
await FollowService.follow_back(item.user_id);
|
||||
|
||||
Taro.showToast({
|
||||
title: "关注成功",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
// 更新列表
|
||||
setFollowList(prevList =>
|
||||
prevList.map(followItem =>
|
||||
followItem.id === item.id
|
||||
? { ...followItem, is_mutual: true }
|
||||
: followItem
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
Taro.showToast({
|
||||
title: "关注失败",
|
||||
title: item.is_mutual ? "取消关注失败" : "关注失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
@@ -130,6 +152,38 @@ const NewFollow = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 处理下拉刷新
|
||||
const handleRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
const res = await FollowService.get_new_fans_list(1, 20);
|
||||
|
||||
if (res.list) {
|
||||
const mappedList = res.list.map((item: any) => ({
|
||||
id: item.id,
|
||||
user_id: item.id,
|
||||
user_avatar: item.avatar_url || "",
|
||||
user_nickname: item.nickname || "匿名用户",
|
||||
user_signature: item.personal_profile || "",
|
||||
city: item.city || "",
|
||||
ntrp_level: item.ntrp_level || "",
|
||||
time: item.follow_time,
|
||||
is_mutual: item.is_mutual || false,
|
||||
}));
|
||||
|
||||
setFollowList(mappedList);
|
||||
}
|
||||
} catch (e) {
|
||||
Taro.showToast({
|
||||
title: "刷新失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染关注项
|
||||
const renderFollowItem = (item: FollowItem) => {
|
||||
return (
|
||||
@@ -148,8 +202,7 @@ const NewFollow = () => {
|
||||
<Text className="user-signature">{item.user_signature}</Text>
|
||||
) : (
|
||||
<View className="action-row">
|
||||
<Text className="action-text">开始关注你了,期待你的回关</Text>
|
||||
<Text className="time-text">{formatTime(item.time)}</Text>
|
||||
<Text className="action-text">{formatTime(item.time)}关注了你</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
@@ -184,6 +237,9 @@ const NewFollow = () => {
|
||||
scrollWithAnimation
|
||||
enhanced
|
||||
showScrollbar={false}
|
||||
refresherEnabled={true}
|
||||
refresherTriggered={refreshing}
|
||||
onRefresherRefresh={handleRefresh}
|
||||
>
|
||||
{followList.length > 0 ? (
|
||||
<View className="follow-list">
|
||||
|
||||
Reference in New Issue
Block a user