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:
@@ -250,14 +250,24 @@ class PostService {
|
||||
}
|
||||
}
|
||||
|
||||
// 分享帖子
|
||||
async sharePost(postId: string): Promise<boolean> {
|
||||
/** 上报分享成功;返回服务端最新 shares_count 供界面同步 */
|
||||
async sharePost(
|
||||
postId: string,
|
||||
body?: { channel?: string }
|
||||
): Promise<{ ok: boolean; shares_count?: number }> {
|
||||
try {
|
||||
const response = await api.post(`/posts/${postId}/share`);
|
||||
return response.code === 0;
|
||||
const response = await api.post<{ success: boolean; shares_count: number }>(
|
||||
`/posts/${postId}/share`,
|
||||
body && body.channel ? { channel: body.channel } : undefined
|
||||
);
|
||||
if (response.code !== 0) {
|
||||
return { ok: false };
|
||||
}
|
||||
const n = response.data?.shares_count;
|
||||
return { ok: true, shares_count: typeof n === 'number' ? n : undefined };
|
||||
} catch (error) {
|
||||
console.error('分享帖子失败:', error);
|
||||
return false;
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user