Files
e-party-iOS/yana/Features/HomeFeature.swift
edwinQQQ fb7ae9e0ad feat: 更新.gitignore,删除需求文档,优化API调试信息
- 在.gitignore中添加忽略项以排除不必要的文件。
- 删除架构分析需求文档以简化项目文档。
- 在APIEndpoints.swift和LoginModels.swift中移除调试信息的异步调用,提升代码简洁性。
- 在EMailLoginFeature.swift和HomeFeature.swift中新增登录流程状态管理,优化用户体验。
- 在多个视图中调整状态管理和导航逻辑,确保一致性和可维护性。
- 更新Xcode项目配置以增强调试信息的输出格式。
2025-07-18 15:57:54 +08:00

121 lines
3.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")
// }