refactor(PostCard, PostCard.legacy): remove legacy PostCard component and update exports
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 8m37s
Frontend CI / ota-android (push) Successful in 10m53s
Frontend CI / build-android-apk (push) Successful in 51m16s

- Deleted the legacy PostCard component to streamline the codebase and improve maintainability.
- Updated exports in PostCard and index files to remove references to the legacy component.
- Adjusted PostCardProps to eliminate legacy properties, ensuring only the new API is supported.
- Enhanced the PostCard component to focus on modern implementation and features.
This commit is contained in:
lafay
2026-03-24 04:23:13 +08:00
parent 82e99d24d8
commit 357c1d4995
24 changed files with 1662 additions and 2243 deletions

View File

@@ -47,6 +47,8 @@ interface PostApiResponse {
username: string;
nickname?: string;
avatar?: string;
is_following?: boolean;
is_following_me?: boolean;
};
}
@@ -102,6 +104,9 @@ export class PostRepository implements IPostRepository {
username: model.author.username,
nickname: model.author.nickname,
avatar: model.author.avatar,
// 关注关系直接透传 API 字段,供详情页关注按钮状态使用
is_following: response.author?.is_following,
is_following_me: response.author?.is_following_me,
} : undefined,
title: model.title,
content: model.content,
@@ -286,20 +291,7 @@ export class PostRepository implements IPostRepository {
*/
async getPostById(id: string): Promise<Post | null> {
try {
// 1. 先查内存缓存
const memoryCached = this.getFromMemoryCache(id);
if (memoryCached) {
return memoryCached;
}
// 2. 查本地数据库缓存
const localCached = await this.getFromLocalCache(id);
if (localCached) {
this.saveToMemoryCache(localCached);
return localCached;
}
// 3. 从API获取
// 详情页优先取最新服务端数据,避免旧缓存导致关注态等关系字段过期
const response = await this.api.get<PostApiResponse>(`/posts/${id}`);
const post = this.mapToPost(response);
@@ -309,10 +301,16 @@ export class PostRepository implements IPostRepository {
return post;
} catch (error) {
// 如果API请求失败,尝试返回本地缓存
// API失败时再回退缓存,保证离线/弱网可用
const memoryCached = this.getFromMemoryCache(id);
if (memoryCached) {
console.warn('[PostRepository] API获取失败使用内存缓存:', error);
return memoryCached;
}
const localCached = await this.getFromLocalCache(id);
if (localCached) {
console.warn('[PostRepository] API获取失败使用本地缓存:', error);
this.saveToMemoryCache(localCached);
return localCached;
}
this.handleError(error, '获取帖子详情');