feat(pagination): add updateItem for in-place list updates and optimize notifications
Some checks failed
Frontend CI / build-and-push-web (push) Failing after 2m48s
Frontend CI / ota-android (push) Successful in 10m30s
Frontend CI / build-android-apk (push) Successful in 39m3s

Add `updateItem` function to cursor pagination hook for updating single items
without full list refresh. Use this in NotificationsScreen to mark messages
as read locally instead of refetching. Also add `is_blocked` detection in
postService and userProfile to show blocked state in profile screen.
This commit is contained in:
lafay
2026-04-25 11:26:13 +08:00
parent ad19bc2af7
commit f16f001f6c
6 changed files with 53 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ interface PostListResponse {
page: number;
page_size: number;
total_pages: number;
is_blocked?: boolean;
}
// 帖子响应 - API直接返回Post对象
@@ -131,7 +132,7 @@ class PostService {
userId: string,
page = 1,
pageSize = 20
): Promise<PaginatedData<Post>> {
): Promise<PaginatedData<Post> & { is_blocked?: boolean }> {
try {
const response = await api.get<PostListResponse>(`/users/${userId}/posts`, {
page,
@@ -368,13 +369,13 @@ class PostService {
async getUserPostsCursor(
userId: string,
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<Post>> {
): Promise<CursorPaginationResponse<Post> & { is_blocked?: boolean }> {
try {
const response = await api.get<any>(
`/users/${userId}/posts`,
params
);
const data = response.data;
if (data && typeof data === 'object' && Array.isArray(data.list)) {
@@ -391,6 +392,7 @@ class PostService {
next_cursor: currentPage < totalPages ? String(currentPage + 1) : null,
prev_cursor: currentPage > 1 ? String(currentPage - 1) : null,
has_more: currentPage < totalPages,
is_blocked: data.is_blocked,
};
}
return {
@@ -398,6 +400,7 @@ class PostService {
next_cursor: data.next_cursor ?? null,
prev_cursor: data.prev_cursor ?? null,
has_more: data.has_more ?? false,
is_blocked: data.is_blocked,
};
}