refactor(platform): extract blurActiveElement to infrastructure module
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 4m47s
Frontend CI / ota-android (push) Successful in 10m48s
Frontend CI / build-android-apk (push) Successful in 1h36m37s

- Centralize duplicated Platform.OS === 'web' blur logic across 16 components
- Add blurActiveElement utility to src/infrastructure/platform module
- Optimize MessageBubble and ImageSegment with React.memo custom comparators
- Add useMemo for computed values in MessageSegmentsRenderer
- Update DTO types with is_system_notice and notice_content fields
- Fix keyboard dismissal order in useChatScreen handleDismiss
- Simplify userStore follow/unfollow state updates
- Remove unnecessary TypeScript type assertions throughout codebase
This commit is contained in:
lafay
2026-04-11 22:35:11 +08:00
parent 6f84e17772
commit 4b5ce1ba21
29 changed files with 679 additions and 222 deletions

View File

@@ -254,18 +254,13 @@ export const useUserStore = create<UserState>((set, get) => {
followUser: async (userId: string) => {
const originalUsers = get().users;
const originalUserCache = get().userCache;
// 乐观更新 users
set(state => ({
users: state.users.map(u =>
u.id === userId
? { ...u, isFollowing: true, followersCount: u.followers_count + 1 }
: u
),
}));
// 乐观更新 userCache
set(state => ({
userCache: Object.fromEntries(
Object.entries(state.userCache).map(([id, user]) => [
id,
@@ -275,35 +270,25 @@ export const useUserStore = create<UserState>((set, get) => {
])
)
}));
try {
await authService.followUser(userId);
} catch (error) {
console.error('关注用户失败:', error);
// 回滚
set({
users: originalUsers,
userCache: originalUserCache
});
set({ users: originalUsers, userCache: originalUserCache });
}
},
// 取消关注 - authService 不管理状态,所以由 store 管理
unfollowUser: async (userId: string) => {
const originalUsers = get().users;
const originalUserCache = get().userCache;
// 乐观更新 users
set(state => ({
users: state.users.map(u =>
u.id === userId
? { ...u, isFollowing: false, followersCount: Math.max(0, u.followers_count - 1) }
: u
),
}));
// 乐观更新 userCache
set(state => ({
userCache: Object.fromEntries(
Object.entries(state.userCache).map(([id, user]) => [
id,
@@ -313,16 +298,12 @@ export const useUserStore = create<UserState>((set, get) => {
])
)
}));
try {
await authService.unfollowUser(userId);
} catch (error) {
console.error('取消关注用户失败:', error);
// 回滚
set({
users: originalUsers,
userCache: originalUserCache
});
set({ users: originalUsers, userCache: originalUserCache });
}
},