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.
This commit is contained in:
@@ -29,6 +29,7 @@ import { useUserStore } from '../../stores';
|
||||
import { useCurrentUser } from '../../stores/authStore';
|
||||
import { postService } from '../../services';
|
||||
import { PostCard, TabBar, SearchBar } from '../../components/business';
|
||||
import type { PostCardAction } from '../../components/business/PostCard';
|
||||
import { Loading, EmptyState, Text, ImageGallery, ImageGridItem, ResponsiveGrid } from '../../components/common';
|
||||
import { HomeStackParamList, RootStackParamList } from '../../navigation/types';
|
||||
import { useResponsive, useResponsiveSpacing } from '../../hooks/useResponsive';
|
||||
@@ -368,6 +369,41 @@ export const HomeScreen: React.FC = () => {
|
||||
setShowImageViewer(true);
|
||||
};
|
||||
|
||||
// 统一处理 PostCard 的所有操作
|
||||
const handlePostAction = (post: Post, action: PostCardAction) => {
|
||||
switch (action.type) {
|
||||
case 'press':
|
||||
handlePostPress(post.id);
|
||||
break;
|
||||
case 'userPress':
|
||||
const authorId = post.author?.id;
|
||||
if (authorId) handleUserPress(authorId);
|
||||
break;
|
||||
case 'like':
|
||||
case 'unlike':
|
||||
handleLike(post);
|
||||
break;
|
||||
case 'comment':
|
||||
handlePostPress(post.id, true);
|
||||
break;
|
||||
case 'bookmark':
|
||||
case 'unbookmark':
|
||||
handleBookmark(post);
|
||||
break;
|
||||
case 'share':
|
||||
handleShare(post);
|
||||
break;
|
||||
case 'imagePress':
|
||||
if (action.payload?.images && action.payload?.imageIndex !== undefined) {
|
||||
handleImagePress(action.payload.images, action.payload.imageIndex);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
handleDeletePost(post.id);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// 跳转到发帖页面(使用 Modal 方式)
|
||||
const handleCreatePost = () => {
|
||||
setShowCreatePost(true);
|
||||
@@ -392,19 +428,12 @@ export const HomeScreen: React.FC = () => {
|
||||
]}>
|
||||
<PostCard
|
||||
post={item}
|
||||
onPress={() => handlePostPress(item.id)}
|
||||
onUserPress={() => authorId && handleUserPress(authorId)}
|
||||
onLike={() => handleLike(item)}
|
||||
onComment={() => handlePostPress(item.id, true)}
|
||||
onBookmark={() => handleBookmark(item)}
|
||||
onShare={() => handleShare(item)}
|
||||
onImagePress={(images, index) => handleImagePress(images, index)}
|
||||
onDelete={() => handleDeletePost(item.id)}
|
||||
onAction={(action) => handlePostAction(item, action)}
|
||||
isPostAuthor={isPostAuthor}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}, [currentUser?.id, handleBookmark, handleDeletePost, handleImagePress, handleLike, handlePostPress, handleShare, handleUserPress, isMobile, listItemWidth, responsiveGap]);
|
||||
}, [currentUser?.id, handlePostAction, isMobile, listItemWidth, responsiveGap]);
|
||||
|
||||
// 估算帖子在瀑布流中的高度(用于均匀分配)
|
||||
const estimatePostHeight = (post: Post, columnWidth: number): number => {
|
||||
|
||||
Reference in New Issue
Block a user