refactor(ImageGallery, HomeScreen, PostService, UserStore): streamline post type handling and improve tab navigation
- 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:
@@ -63,7 +63,7 @@ class PostManager extends CacheBus<PostManagerSnapshot, PostManagerEvent> {
|
||||
}
|
||||
|
||||
async getPosts(
|
||||
type = 'recommend',
|
||||
type = 'hot',
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
forceRefresh = false
|
||||
|
||||
@@ -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(),
|
||||
]);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user