refactor(PostCard, PostCard.legacy): remove legacy PostCard component and update exports
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 8m37s
Frontend CI / ota-android (push) Successful in 10m53s
Frontend CI / build-android-apk (push) Successful in 51m16s

- Deleted the legacy PostCard component to streamline the codebase and improve maintainability.
- Updated exports in PostCard and index files to remove references to the legacy component.
- Adjusted PostCardProps to eliminate legacy properties, ensuring only the new API is supported.
- Enhanced the PostCard component to focus on modern implementation and features.
This commit is contained in:
lafay
2026-03-24 04:23:13 +08:00
parent 82e99d24d8
commit 357c1d4995
24 changed files with 1662 additions and 2243 deletions

View File

@@ -512,14 +512,7 @@ export const HomeScreen: React.FC = () => {
<PostCard
post={post}
variant="grid"
onPress={() => handlePostPress(post.id)}
onUserPress={() => authorId && handleUserPress(authorId)}
onLike={() => handleLike(post)}
onComment={() => handlePostPress(post.id, true)}
onBookmark={() => handleBookmark(post)}
onShare={() => handleShare(post)}
onImagePress={(images, index) => handleImagePress(images, index)}
onDelete={() => handleDeletePost(post.id)}
onAction={(action) => handlePostAction(post, action)}
isPostAuthor={isPostAuthor}
/>
</View>
@@ -579,15 +572,8 @@ export const HomeScreen: React.FC = () => {
<PostCard
key={post.id}
post={post}
variant={viewMode === 'grid' ? 'grid' : 'default'}
onPress={() => handlePostPress(post.id)}
onUserPress={() => authorId && handleUserPress(authorId)}
onLike={() => handleLike(post)}
onComment={() => handlePostPress(post.id, true)}
onBookmark={() => handleBookmark(post)}
onShare={() => handleShare(post)}
onImagePress={(images, index) => handleImagePress(images, index)}
onDelete={() => handleDeletePost(post.id)}
variant={viewMode === 'grid' ? 'grid' : 'list'}
onAction={(action) => handlePostAction(post, action)}
isPostAuthor={isPostAuthor}
/>
);

View File

@@ -281,8 +281,25 @@ export const PostDetailScreen: React.FC = () => {
if (!post?.author) return;
const author = post.author;
const handleBackPress = () => {
if (navigation.canGoBack()) {
navigation.goBack();
return;
}
navigation.navigate('Main', {
screen: 'HomeTab',
params: { screen: 'Home', params: undefined },
});
};
navigation.setOptions({
headerBackVisible: false,
headerTitleAlign: 'left',
headerLeft: () => (
<TouchableOpacity onPress={handleBackPress} style={styles.headerBackButton} hitSlop={8}>
<MaterialCommunityIcons name="arrow-left" size={24} color={colors.text.primary} />
</TouchableOpacity>
),
headerTitle: () => (
<View style={styles.headerContainer}>
<TouchableOpacity
@@ -298,7 +315,9 @@ export const PostDetailScreen: React.FC = () => {
<View style={styles.headerUserInfo}>
<TouchableOpacity onPress={() => handleUserPress(author.id)}>
<Text style={styles.headerNickname} numberOfLines={1}>
{author.nickname}
{author.nickname && author.nickname.length > 10
? `${author.nickname.slice(0, 10)}...`
: author.nickname}
</Text>
</TouchableOpacity>
</View>
@@ -1701,7 +1720,7 @@ const styles = StyleSheet.create({
flexDirection: 'row',
alignItems: 'center',
flex: 1,
marginLeft: -8,
marginLeft: spacing.sm,
},
headerAvatarWrapper: {
marginRight: spacing.sm,
@@ -1720,6 +1739,12 @@ const styles = StyleSheet.create({
alignItems: 'center',
marginRight: spacing.sm,
},
headerBackButton: {
paddingHorizontal: spacing.xs,
paddingVertical: spacing.xs,
marginLeft: spacing.xs,
marginRight: spacing.sm,
},
// 帖子容器
postContainer: {
backgroundColor: colors.background.paper,

View File

@@ -22,6 +22,7 @@ import { Post, User } from '../../types';
import { useUserStore } from '../../stores';
import { postService, authService } from '../../services';
import { PostCard, TabBar, SearchBar } from '../../components/business';
import type { PostCardAction } from '../../components/business/PostCard';
import { Avatar, EmptyState, Text, ResponsiveGrid, Loading } from '../../components/common';
import { HomeStackParamList } from '../../navigation/types';
import { useResponsive, useResponsiveSpacing, useResponsiveValue } from '../../hooks/useResponsive';
@@ -175,6 +176,41 @@ export const SearchScreen: React.FC<SearchScreenProps> = ({ onBack, navigation:
navigation.navigate('UserProfile', { userId });
};
// 统一处理 PostCard 的操作(搜索页不支持删除)
const handlePostAction = (post: Post, action: PostCardAction) => {
switch (action.type) {
case 'press':
handlePostPress(post.id);
break;
case 'userPress':
if (post.author?.id) {
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 'imagePress':
case 'delete':
break;
}
};
// 获取当前搜索类型
const getSearchType = (): SearchType => {
switch (activeIndex) {
@@ -222,13 +258,9 @@ export const SearchScreen: React.FC<SearchScreenProps> = ({ onBack, navigation:
<PostCard
key={post.id}
post={post}
onPress={() => handlePostPress(post.id)}
onUserPress={() => post.author ? handleUserPress(post.author.id) : () => {}}
onLike={() => {}}
onComment={() => handlePostPress(post.id, true)}
onBookmark={() => {}}
onShare={() => {}}
compact={isMobile}
onAction={(action) => handlePostAction(post, action)}
variant="list"
features={isMobile ? 'compact' : 'full'}
/>
))}
</ResponsiveGrid>
@@ -248,13 +280,9 @@ export const SearchScreen: React.FC<SearchScreenProps> = ({ onBack, navigation:
renderItem={({ item }) => (
<PostCard
post={item}
onPress={() => handlePostPress(item.id)}
onUserPress={() => item.author ? handleUserPress(item.author.id) : () => {}}
onLike={() => {}}
onComment={() => handlePostPress(item.id, true)}
onBookmark={() => {}}
onShare={() => {}}
compact
onAction={(action) => handlePostAction(item, action)}
variant="list"
features="compact"
/>
)}
keyExtractor={item => item.id}