refactor(ImageGallery, HomeScreen, PostService, UserStore): streamline post type handling and improve tab navigation
Some checks failed
Frontend CI / build-and-push-web (push) Successful in 2m37s
Frontend CI / ota-android (push) Has been cancelled
Frontend CI / build-android-apk (push) Has been cancelled

- Updated ImageGallery to manage loading states more effectively and prevent unnecessary updates.
- Refactored HomeScreen to remove the 'recommend' post type, simplifying the post type options.
- Adjusted PostService and UserStore to eliminate references to 'recommend', ensuring consistency across the application.
- Enhanced tab navigation in SimpleMobileTabNavigator to optimize rendering and manage mounted tabs more efficiently.
- Improved error handling and loading states in various components for better user experience.
This commit is contained in:
lafay
2026-03-24 05:18:22 +08:00
parent 357c1d4995
commit 48339384d2
9 changed files with 72 additions and 34 deletions

View File

@@ -34,7 +34,7 @@ interface UserState {
// 操作
fetchUser: (userId: string) => Promise<User | undefined>;
fetchUserPosts: (userId: string, page?: number) => Promise<Post[]>;
fetchPosts: (type: 'recommend' | 'follow' | 'hot' | 'latest', page?: number) => Promise<PaginatedData<Post>>;
fetchPosts: (type: 'follow' | 'hot' | 'latest', page?: number) => Promise<PaginatedData<Post>>;
fetchNotifications: (type?: string, page?: number) => Promise<Notification[]>;
markNotificationAsRead: (notificationId: string) => Promise<void>;
markAllNotificationsAsRead: () => Promise<void>;
@@ -108,16 +108,13 @@ export const useUserStore = create<UserState>((set, get) => {
},
// 获取帖子列表(首页)
fetchPosts: async (type: 'recommend' | 'follow' | 'hot' | 'latest', page = 1) => {
fetchPosts: async (type: 'follow' | 'hot' | 'latest', page = 1) => {
set({ isLoadingPosts: true });
try {
let response;
switch (type) {
case 'recommend':
response = await postService.getRecommendedPosts(page);
break;
case 'follow':
response = await postService.getFollowingPosts(page);
break;
@@ -332,7 +329,7 @@ export const useUserStore = create<UserState>((set, get) => {
// 刷新所有数据
refreshAll: async () => {
await Promise.all([
get().fetchPosts('recommend', 1),
get().fetchPosts('latest', 1),
get().fetchNotificationBadge(),
]);
},