Files
e-party-iOS/yana/Views/MeDynamicView.swift
edwinQQQ 8b09653c4c feat: 更新动态功能,新增我的动态视图及相关状态管理
- 在HomeFeature中添加MeDynamicFeature以管理用户动态状态。
- 在MainFeature中集成MeDynamicFeature,支持动态内容的加载与展示。
- 新增MeDynamicView以展示用户的动态列表,支持下拉刷新和上拉加载更多功能。
- 更新MeView以集成用户动态视图,提升用户体验。
- 在APIEndpoints中新增getMyDynamic端点以支持获取用户动态信息。
- 更新DynamicsModels以适应新的动态数据结构,确保数据解析的准确性。
- 在OptimizedDynamicCardView中优化图片处理逻辑,提升动态展示效果。
- 更新相关视图组件以支持动态内容的展示与交互,增强用户体验。
2025-07-23 19:17:49 +08:00

76 lines
3.3 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 SwiftUI
import ComposableArchitecture
struct MeDynamicView: View {
let store: StoreOf<MeDynamicFeature>
// uid
@State private var showDeleteAlert = false
@State private var selectedMoment: MomentsInfo?
var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
Group {
if viewStore.isLoading && viewStore.dynamics.isEmpty {
ProgressView("加载中...")
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else if let error = viewStore.error {
VStack(spacing: 16) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 40))
.foregroundColor(.yellow)
Text(error)
.foregroundColor(.red)
Button("重试") {
viewStore.send(.onAppear)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else if viewStore.dynamics.isEmpty {
VStack(spacing: 16) {
Image(systemName: "tray")
.font(.system(size: 40))
.foregroundColor(.gray)
Text("暂无动态")
.foregroundColor(.white.opacity(0.8))
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
ScrollView {
LazyVStack(spacing: 12) {
ForEach(Array(viewStore.dynamics.enumerated()), id: \.element.dynamicId) { index, moment in
OptimizedDynamicCardView(moment: moment, allMoments: viewStore.dynamics, currentIndex: index)
.padding(.horizontal, 12)
.onLongPressGesture {
if viewStore.uid == moment.uid {
selectedMoment = moment
showDeleteAlert = true
}
}
}
if viewStore.hasMore {
ProgressView()
.onAppear {
viewStore.send(.loadMore)
}
}
}
.padding(.top, 8)
}
.refreshable {
viewStore.send(.refresh)
}
}
}
.alert("确认删除该动态?", isPresented: $showDeleteAlert, presenting: selectedMoment) { moment in
Button("删除", role: .destructive) {
// TODO: Action viewStore.send(.delete(moment.dynamicId))
}
Button("取消", role: .cancel) {}
} message: { _ in
Text("此操作不可恢复")
}
}
}
}