feat(pagination): add updateItem for in-place list updates and optimize notifications
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:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user