refactor: standardize pagination response structure and enhance cursor handling
- Update various services and hooks to replace 'items' with 'list' for consistency in pagination responses. - Modify PostRepository, commentService, groupService, messageService, and postService to align with the new response structure. - Enhance cursor pagination logic in hooks and components to ensure proper handling of pagination states. - Refactor HomeScreen, PostDetailScreen, SearchScreen, and other components to utilize the updated pagination structure.
This commit is contained in:
@@ -231,9 +231,12 @@ export class PostRepository implements IPostRepository {
|
||||
try {
|
||||
const queryParams: Record<string, any> = {};
|
||||
|
||||
if (params?.page) queryParams.page = params.page;
|
||||
if (params?.page !== undefined) queryParams.page = params.page;
|
||||
if (params?.pageSize) queryParams.page_size = params.pageSize;
|
||||
if (params?.cursor) queryParams.cursor = params.cursor;
|
||||
// 支持 cursor 参数:空字符串也传递,用于启动 cursor 模式
|
||||
if (params?.cursor !== undefined && params?.cursor !== null) {
|
||||
queryParams.cursor = params.cursor;
|
||||
}
|
||||
if (params?.post_type) queryParams.tab = params.post_type;
|
||||
if (params?.communityId) queryParams.community_id = params.communityId;
|
||||
if (params?.authorId) queryParams.author_id = params.authorId;
|
||||
@@ -253,9 +256,16 @@ export class PostRepository implements IPostRepository {
|
||||
this.saveToLocalCache(post);
|
||||
});
|
||||
|
||||
// 计算 hasMore:优先使用 has_more,否则通过 page/total_pages 计算
|
||||
let hasMore = response.has_more;
|
||||
if (hasMore === undefined && response.page !== undefined && response.total_pages !== undefined) {
|
||||
hasMore = response.page < response.total_pages;
|
||||
}
|
||||
hasMore = hasMore ?? false;
|
||||
|
||||
return {
|
||||
posts,
|
||||
hasMore: response.has_more ?? false,
|
||||
hasMore,
|
||||
nextCursor: response.next_cursor,
|
||||
total: response.total,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user