feat(ProcessPostUseCase, HomeScreen, PostDetailScreen, PostService): implement share count synchronization after post sharing
- Added applyShareCountUpdate method in ProcessPostUseCase to synchronize share counts across post lists and details. - Updated sharePost method in PostService to return the latest shares_count from the server. - Modified share handling in HomeScreen and PostDetailScreen to utilize the new share count synchronization logic after a successful share operation. - Enhanced error handling for share operations to improve user feedback.
This commit is contained in:
@@ -333,6 +333,35 @@ class ProcessPostUseCase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享计数上报成功后,同步各列表与详情中的分享数
|
||||
*/
|
||||
applyShareCountUpdate(postId: string, sharesCount: number): void {
|
||||
this.postsState.forEach((state, key) => {
|
||||
const index = state.posts.findIndex((p) => p.id === postId);
|
||||
if (index !== -1) {
|
||||
const newPosts = [...state.posts];
|
||||
const cur = newPosts[index];
|
||||
newPosts[index] = {
|
||||
...cur,
|
||||
sharesCount,
|
||||
shares_count: sharesCount,
|
||||
};
|
||||
this.updatePostsState(key, { posts: newPosts });
|
||||
}
|
||||
});
|
||||
const detail = this.getPostDetailState(postId);
|
||||
if (detail.post) {
|
||||
this.updatePostDetailState(postId, {
|
||||
post: {
|
||||
...detail.post,
|
||||
sharesCount,
|
||||
shares_count: sharesCount,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 帖子列表操作 ====================
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user