Remove unnecessary console logs and replace them with void expressions for better performance and cleaner code. Update error logging to use console.error for consistency. This change enhances code readability and reduces console noise during execution.
Some checks failed
Frontend CI / build-and-push-web (push) Failing after 2m18s
Frontend CI / ota-android (push) Failing after 6m15s
Frontend CI / build-android-apk (push) Failing after 29m51s

This commit is contained in:
2026-03-24 03:02:54 +08:00
parent 5c9cb6acea
commit 82e99d24d8
13 changed files with 728 additions and 32 deletions

View File

@@ -22,6 +22,7 @@ import { Post } from '../../types';
import { useAuthStore, useUserStore } from '../../stores';
import { postService } from '../../services';
import { UserProfileHeader, PostCard, TabBar } from '../../components/business';
import { PostCardAction } from '../../components/business/PostCard';
import { Loading, EmptyState, Text } from '../../components/common';
import { ResponsiveContainer } from '../../components/common';
import { useResponsive } from '../../hooks';
@@ -245,6 +246,37 @@ export const ProfileScreen: React.FC = () => {
}
}, []);
// 统一的 PostCard Action 处理
const handlePostAction = useCallback((post: Post, action: PostCardAction) => {
switch (action.type) {
case 'press':
handlePostPress(post.id);
break;
case 'userPress':
if (post.author) {
handleUserPress(post.author.id);
}
break;
case 'like':
case 'unlike':
post.is_liked ? postService.unlikePost(post.id) : postService.likePost(post.id);
break;
case 'comment':
handlePostPress(post.id, true);
break;
case 'bookmark':
case 'unbookmark':
post.is_favorited ? postService.unfavoritePost(post.id) : postService.favoritePost(post.id);
break;
case 'share':
// 暂不处理分享
break;
case 'delete':
handleDeletePost(post.id);
break;
}
}, [handlePostPress, handleUserPress, handleDeletePost]);
// 渲染内容
const renderContent = useCallback(() => {
if (loading) return <Loading />;
@@ -273,13 +305,7 @@ export const ProfileScreen: React.FC = () => {
]}>
<PostCard
post={post}
onPress={() => handlePostPress(post.id)}
onUserPress={() => post.author ? handleUserPress(post.author.id) : () => {}}
onLike={() => post.is_liked ? postService.unlikePost(post.id) : postService.likePost(post.id)}
onComment={() => handlePostPress(post.id, true)}
onBookmark={() => post.is_favorited ? postService.unfavoritePost(post.id) : postService.favoritePost(post.id)}
onShare={() => {}}
onDelete={() => handleDeletePost(post.id)}
onAction={(action) => handlePostAction(post, action)}
isPostAuthor={isPostAuthor}
/>
</View>

View File

@@ -23,6 +23,7 @@ import { useCurrentUser } from '../../stores/authStore';
import { authService, postService, messageService } from '../../services';
import { userManager } from '../../stores/userManager';
import { UserProfileHeader, PostCard, TabBar } from '../../components/business';
import { PostCardAction } from '../../components/business/PostCard';
import { Loading, EmptyState, ResponsiveContainer } from '../../components/common';
import { useResponsive } from '../../hooks';
import { HomeStackParamList, RootStackParamList } from '../../navigation/types';
@@ -218,6 +219,39 @@ export const UserScreen: React.FC = () => {
}
};
// 统一处理 PostCard 的所有操作
const handlePostAction = (post: Post, action: PostCardAction) => {
switch (action.type) {
case 'press':
handlePostPress(post.id);
break;
case 'userPress':
if (post.author) handleUserPress(post.author.id);
break;
case 'like':
postService.likePost(post.id);
break;
case 'unlike':
postService.unlikePost(post.id);
break;
case 'comment':
handlePostPress(post.id, true);
break;
case 'bookmark':
postService.favoritePost(post.id);
break;
case 'unbookmark':
postService.unfavoritePost(post.id);
break;
case 'share':
// 暂不处理
break;
case 'delete':
handleDeletePost(post.id);
break;
}
};
// 跳转到聊天界面
const handleMessage = async () => {
if (!user) return;
@@ -317,13 +351,7 @@ export const UserScreen: React.FC = () => {
]}>
<PostCard
post={post}
onPress={() => handlePostPress(post.id)}
onUserPress={() => post.author ? handleUserPress(post.author.id) : () => {}}
onLike={() => post.is_liked ? postService.unlikePost(post.id) : postService.likePost(post.id)}
onComment={() => handlePostPress(post.id, true)}
onBookmark={() => post.is_favorited ? postService.unfavoritePost(post.id) : postService.favoritePost(post.id)}
onShare={() => {}}
onDelete={() => handleDeletePost(post.id)}
onAction={(action) => handlePostAction(post, action)}
isPostAuthor={isPostAuthor}
/>
</View>
@@ -357,13 +385,7 @@ export const UserScreen: React.FC = () => {
]}>
<PostCard
post={post}
onPress={() => handlePostPress(post.id)}
onUserPress={() => post.author ? handleUserPress(post.author.id) : () => {}}
onLike={() => post.is_liked ? postService.unlikePost(post.id) : postService.likePost(post.id)}
onComment={() => handlePostPress(post.id, true)}
onBookmark={() => post.is_favorited ? postService.unfavoritePost(post.id) : postService.favoritePost(post.id)}
onShare={() => {}}
onDelete={() => handleDeletePost(post.id)}
onAction={(action) => handlePostAction(post, action)}
isPostAuthor={isPostAuthor}
/>
</View>