
- 在.gitignore中添加忽略项以排除不必要的文件。 - 删除架构分析需求文档以简化项目文档。 - 在APIEndpoints.swift和LoginModels.swift中移除调试信息的异步调用,提升代码简洁性。 - 在EMailLoginFeature.swift和HomeFeature.swift中新增登录流程状态管理,优化用户体验。 - 在多个视图中调整状态管理和导航逻辑,确保一致性和可维护性。 - 更新Xcode项目配置以增强调试信息的输出格式。
121 lines
3.6 KiB
Swift
121 lines
3.6 KiB
Swift
import Foundation
|
||
import ComposableArchitecture
|
||
|
||
@Reducer
|
||
struct HomeFeature {
|
||
@ObservableState
|
||
struct State: Equatable {
|
||
var isInitialized = false
|
||
var userInfo: UserInfo?
|
||
var accountModel: AccountModel?
|
||
var error: String?
|
||
|
||
// 设置页面相关状态
|
||
var isSettingPresented = false
|
||
var settingState = SettingFeature.State()
|
||
|
||
// 新增:Feed 状态
|
||
var feedState = FeedFeature.State()
|
||
|
||
// 新增:登出状态
|
||
var isLoggedOut = false
|
||
}
|
||
|
||
enum Action {
|
||
case onAppear
|
||
case loadUserInfo
|
||
case userInfoLoaded(UserInfo?)
|
||
case loadAccountModel
|
||
case accountModelLoaded(AccountModel?)
|
||
case logoutTapped
|
||
case logout
|
||
|
||
// 设置页面相关actions
|
||
case settingDismissed
|
||
case setting(SettingFeature.Action)
|
||
|
||
// 新增:Feed actions
|
||
case feed(FeedFeature.Action)
|
||
|
||
// 新增:登出完成
|
||
case logoutCompleted
|
||
}
|
||
|
||
var body: some ReducerOf<Self> {
|
||
Scope(state: \ .settingState, action: \ .setting) {
|
||
SettingFeature()
|
||
}
|
||
|
||
// 新增:Feed Scope
|
||
Scope(state: \ .feedState, action: \ .feed) {
|
||
FeedFeature()
|
||
}
|
||
|
||
Reduce { state, action in
|
||
switch action {
|
||
case .onAppear:
|
||
#if DEBUG
|
||
return .none
|
||
#endif
|
||
state.isInitialized = true
|
||
return .concatenate(
|
||
.send(.loadUserInfo),
|
||
.send(.loadAccountModel)
|
||
)
|
||
|
||
case .loadUserInfo:
|
||
// 从本地存储加载用户信息
|
||
return .run { send in
|
||
let userInfo = await UserInfoManager.getUserInfo()
|
||
await send(.userInfoLoaded(userInfo))
|
||
}
|
||
|
||
case let .userInfoLoaded(userInfo):
|
||
state.userInfo = userInfo
|
||
return .none
|
||
|
||
case .loadAccountModel:
|
||
// 从本地存储加载账户信息
|
||
return .run { send in
|
||
let accountModel = await UserInfoManager.getAccountModel()
|
||
await send(.accountModelLoaded(accountModel))
|
||
}
|
||
|
||
case let .accountModelLoaded(accountModel):
|
||
state.accountModel = accountModel
|
||
return .none
|
||
|
||
case .logoutTapped:
|
||
return .send(.logout)
|
||
|
||
case .logout:
|
||
// 清除所有认证数据并设置登出状态
|
||
return .run { send in
|
||
await UserInfoManager.clearAllAuthenticationData()
|
||
await send(.logoutCompleted)
|
||
}
|
||
|
||
case .logoutCompleted:
|
||
state.isLoggedOut = true
|
||
return .none
|
||
|
||
case .settingDismissed:
|
||
state.isSettingPresented = false
|
||
return .none
|
||
|
||
case .setting:
|
||
// 由子reducer处理
|
||
return .none
|
||
case .feed(_):
|
||
// FeedFeature 的 action 已由 Scope 自动处理,无需额外处理
|
||
return .none
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 移除:未使用的通知名称定义
|
||
// extension Notification.Name {
|
||
// static let homeLogout = Notification.Name("homeLogout")
|
||
// }
|