feat: 增强FeedListFeature和MeFeature的首次加载逻辑

- 在FeedListFeature和MeFeature中新增isFirstLoad状态,确保仅在首次加载时请求数据。
- 更新MainView以简化视图切换逻辑,使用isHidden修饰符控制视图显示。
- 新增View+isHidden扩展,提供视图隐藏功能,提升代码可读性和复用性。
This commit is contained in:
edwinQQQ
2025-07-24 10:20:12 +08:00
parent 3a74547684
commit 25fec8a2e6
5 changed files with 32 additions and 31 deletions

View File

@@ -5,6 +5,7 @@ import ComposableArchitecture
struct MeFeature {
@Dependency(\.apiService) var apiService
struct State: Equatable {
var isFirstLoad: Bool = true
var userInfo: UserInfo?
var isLoadingUserInfo: Bool = false
var userInfoError: String?
@@ -32,17 +33,9 @@ struct MeFeature {
func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .onAppear:
guard state.uid > 0 else { return .none }
state.isLoadingUserInfo = true
state.isLoadingMoments = true
state.userInfoError = nil
state.momentsError = nil
state.page = 1
state.hasMore = true
return .merge(
fetchUserInfo(uid: state.uid),
fetchMoments(uid: state.uid, page: 1, pageSize: state.pageSize)
)
guard state.isFirstLoad else { return .none }
state.isFirstLoad = false
return .send(.refresh)
case .refresh:
guard state.uid > 0 else { return .none }
state.isRefreshing = true