diff --git a/yana/Features/AppSettingFeature.swift b/yana/Features/AppSettingFeature.swift index 4664ba8..3b0b2b8 100644 --- a/yana/Features/AppSettingFeature.swift +++ b/yana/Features/AppSettingFeature.swift @@ -23,8 +23,7 @@ struct AppSettingFeature { // 用户信息相关 case loadUserInfo - case userInfoLoaded(UserInfo?) - case userInfoLoadFailed(String) + case userInfoResponse(Result) // WebView 导航 case personalInfoPermissionsTapped @@ -58,27 +57,33 @@ struct AppSettingFeature { state.isLoadingUserInfo = true state.userInfoError = nil return .run { send in - let currentUid = await UserInfoManager.getCurrentUserId() - if let userInfo = await UserInfoManager.fetchUserInfoFromServer( - uid: currentUid, - apiService: apiService - ) { - await send(.userInfoLoaded(userInfo)) - } else { - await send(.userInfoLoadFailed("获取用户信息失败")) + do { + if let userInfo = await UserInfoManager.getUserInfo() { + await send(.userInfoResponse(.success(userInfo))) + } else { + await send(.userInfoResponse(.failure(APIError.custom("用户信息不存在")))) + } + } catch { + let apiError: APIError + if let error = error as? APIError { + apiError = error + } else { + apiError = APIError.custom(error.localizedDescription) + } + await send(.userInfoResponse(.failure(apiError))) } } - case let .userInfoLoaded(userInfo): - state.isLoadingUserInfo = false + case let .userInfoResponse(.success(userInfo)): state.userInfo = userInfo - state.nickname = userInfo?.nick ?? "hahahaha" - state.avatarURL = userInfo?.avatar + state.nickname = userInfo.nick ?? "" + state.avatarURL = userInfo.avatar + state.isLoadingUserInfo = false return .none - case let .userInfoLoadFailed(error): + case let .userInfoResponse(.failure(error)): + state.userInfoError = error.localizedDescription state.isLoadingUserInfo = false - state.userInfoError = error return .none case .personalInfoPermissionsTapped: diff --git a/yana/Utils/COSManager.swift b/yana/Utils/COSManager.swift index f29b559..30191a1 100644 --- a/yana/Utils/COSManager.swift +++ b/yana/Utils/COSManager.swift @@ -1,5 +1,4 @@ import Foundation -import ComposableArchitecture import QCloudCOSXML // MARK: - 腾讯云 COS 管理器