feat(pagination): implement cursor-based pagination across the app

Add useCursorPagination hook and update multiple screens and services
to use cursor-based pagination for better performance and consistency.

- Add useCursorPagination hook with deduplication and caching support
- Add cursor pagination types to infrastructure layer
- Refactor HomeScreen, PostDetailScreen, SearchScreen for posts/comments
- Refactor GroupMembersScreen, JoinGroupScreen for groups/members
- Refactor MessageListScreen, NotificationsScreen for messages
- Update post, message, group, comment, notification services with cursor endpoints
- Add CursorPaginationRequest/Response DTOs
- Remove deprecated OPTIMIZATION_DESIGN.md documentation
This commit is contained in:
lafay
2026-03-20 23:00:27 +08:00
parent a005fb0a15
commit 8a0aea1c59
20 changed files with 2464 additions and 2166 deletions

View File

@@ -23,6 +23,8 @@ import {
MyMemberInfoResponse,
SetGroupAvatarRequest,
HandleGroupRequestAction,
CursorPaginationRequest,
CursorPaginationResponse,
} from '../types/dto';
// 群组服务类(纯 API 层)
@@ -321,6 +323,86 @@ class GroupService {
);
}
// ==================== 游标分页方法 ====================
/**
* 获取群组列表(游标分页)
* GET /api/v1/groups/cursor
* @param params 游标分页请求参数
*/
async getGroupsCursor(
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<GroupResponse>> {
try {
const response = await api.get<CursorPaginationResponse<GroupResponse>>('/groups/cursor', {
params,
});
return response.data;
} catch (error) {
console.error('获取群组列表失败:', error);
return {
items: [],
next_cursor: null,
prev_cursor: null,
has_more: false,
};
}
}
/**
* 获取群组成员列表(游标分页)
* GET /api/v1/groups/:id/members/cursor
* @param groupId 群组ID
* @param params 游标分页请求参数
*/
async getGroupMembersCursor(
groupId: number | string,
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<GroupMemberResponse>> {
try {
const response = await api.get<CursorPaginationResponse<GroupMemberResponse>>(
`/groups/${encodeURIComponent(String(groupId))}/members/cursor`,
{ params }
);
return response.data;
} catch (error) {
console.error('获取群组成员列表失败:', error);
return {
items: [],
next_cursor: null,
prev_cursor: null,
has_more: false,
};
}
}
/**
* 获取群公告列表(游标分页)
* GET /api/v1/groups/:id/announcements/cursor
* @param groupId 群组ID
* @param params 游标分页请求参数
*/
async getGroupAnnouncementsCursor(
groupId: number | string,
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<GroupAnnouncementResponse>> {
try {
const response = await api.get<CursorPaginationResponse<GroupAnnouncementResponse>>(
`/groups/${encodeURIComponent(String(groupId))}/announcements/cursor`,
{ params }
);
return response.data;
} catch (error) {
console.error('获取群公告列表失败:', error);
return {
items: [],
next_cursor: null,
prev_cursor: null,
has_more: false,
};
}
}
// ==================== 兼容旧API的方法将逐步废弃 ====================
/**