1
This commit is contained in:
@@ -23,6 +23,7 @@ interface CommentReplyItem {
|
||||
const CommentReply = () => {
|
||||
const [commentList, setCommentList] = useState<CommentReplyItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
getCommentReplyList();
|
||||
@@ -111,6 +112,42 @@ const CommentReply = () => {
|
||||
Taro.navigateBack();
|
||||
};
|
||||
|
||||
// 处理下拉刷新
|
||||
const handleRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
const res = await commentService.getMyActivities({
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
});
|
||||
|
||||
if (res.code === 0 && res.data) {
|
||||
const mappedList = res.data.rows.map((item: CommentActivity) => ({
|
||||
id: item.id,
|
||||
user_avatar: item.user?.avatar_url || "",
|
||||
user_nickname: item.user?.nickname || "匿名用户",
|
||||
action_type: item.type === "reply" ? "reply" as const : "comment" as const,
|
||||
time: item.create_time,
|
||||
content: item.content || "",
|
||||
original_comment: item.parent_comment?.content || "",
|
||||
activity_image: item.game?.image_list?.[0] || "",
|
||||
activity_id: item.game_id,
|
||||
activity_title: item.game?.title || "",
|
||||
}));
|
||||
|
||||
setCommentList(mappedList);
|
||||
}
|
||||
} catch (e) {
|
||||
Taro.showToast({
|
||||
title: "刷新失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染评论/回复项
|
||||
const renderCommentItem = (item: CommentReplyItem) => {
|
||||
const actionText = item.action_type === "comment" ? "评论了你的球局" : "回复了你的评论";
|
||||
@@ -183,6 +220,9 @@ const CommentReply = () => {
|
||||
scrollWithAnimation
|
||||
enhanced
|
||||
showScrollbar={false}
|
||||
refresherEnabled={true}
|
||||
refresherTriggered={refreshing}
|
||||
onRefresherRefresh={handleRefresh}
|
||||
>
|
||||
{commentList.length > 0 ? (
|
||||
<View className="comment-list">
|
||||
|
||||
@@ -30,6 +30,7 @@ const Message = () => {
|
||||
const [messageList, setMessageList] = useState<MessageItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [reachedBottom, setReachedBottom] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
// 获取消息列表
|
||||
const getNoticeList = async () => {
|
||||
@@ -96,6 +97,25 @@ const Message = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 处理下拉刷新
|
||||
const handleRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
const res = await noticeService.getNotificationList({});
|
||||
if (res.code === 0) {
|
||||
setMessageList(res.data.list || []);
|
||||
}
|
||||
} catch (e) {
|
||||
Taro.showToast({
|
||||
title: "刷新失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化时间显示
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return "";
|
||||
@@ -173,6 +193,9 @@ const Message = () => {
|
||||
showScrollbar={false}
|
||||
lowerThreshold={50}
|
||||
onScrollToLower={handleScrollToLower}
|
||||
refresherEnabled={true}
|
||||
refresherTriggered={refreshing}
|
||||
onRefresherRefresh={handleRefresh}
|
||||
>
|
||||
{filteredMessages.length > 0 ? (
|
||||
<View className="message-cards">
|
||||
|
||||
@@ -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