
- 在APIEndpoints中新增动态点赞和删除端点。 - 实现LikeDynamicRequest和DeleteDynamicRequest结构体,支持动态点赞和删除请求。 - 在DetailFeature中添加点赞和删除动态的逻辑,提升用户交互体验。 - 更新FeedListFeature以支持动态详情视图的展示,增强用户体验。 - 新增DetailView以展示动态详情,包含点赞和删除功能。
122 lines
4.6 KiB
Swift
122 lines
4.6 KiB
Swift
import SwiftUI
|
||
import ComposableArchitecture
|
||
|
||
struct DetailView: View {
|
||
@State var store: StoreOf<DetailFeature>
|
||
// @Environment(\.dismiss) private var dismiss
|
||
let onLikeSuccess: ((Int, Bool) -> Void)?
|
||
|
||
init(store: StoreOf<DetailFeature>, onLikeSuccess: ((Int, Bool) -> Void)? = nil) {
|
||
self.store = store
|
||
self.onLikeSuccess = onLikeSuccess
|
||
}
|
||
|
||
var body: some View {
|
||
ScrollView {
|
||
VStack(spacing: 0) {
|
||
// 使用OptimizedDynamicCardView显示动态内容
|
||
OptimizedDynamicCardView(
|
||
moment: store.moment,
|
||
allMoments: [store.moment], // 详情页只有一个动态
|
||
currentIndex: 0,
|
||
onImageTap: { images, index in
|
||
store.send(.showImagePreview(images, index))
|
||
},
|
||
onLikeTap: { dynamicId, uid, likedUid, worldId in
|
||
store.send(.likeDynamic(dynamicId, uid, likedUid, worldId))
|
||
},
|
||
isLikeLoading: store.isLikeLoading,
|
||
isDetailMode: true // 详情页模式,点击卡片不跳转
|
||
)
|
||
.padding(.horizontal, 16)
|
||
.padding(.top, 16)
|
||
}
|
||
}
|
||
.navigationTitle(NSLocalizedString("detail.title", comment: "Detail page title"))
|
||
.navigationBarTitleDisplayMode(.inline)
|
||
.toolbar {
|
||
ToolbarItem(placement: .navigationBarTrailing) {
|
||
// 只有当动态的uid与当前登录用户uid相同时才显示删除按钮
|
||
if isCurrentUserDynamic {
|
||
Button(action: {
|
||
store.send(.deleteDynamic)
|
||
}) {
|
||
if store.isDeleteLoading {
|
||
ProgressView()
|
||
.progressViewStyle(CircularProgressViewStyle(tint: .red))
|
||
.scaleEffect(0.8)
|
||
} else {
|
||
Image(systemName: "trash")
|
||
.foregroundColor(.red)
|
||
}
|
||
}
|
||
.disabled(store.isDeleteLoading)
|
||
}
|
||
}
|
||
}
|
||
.onAppear {
|
||
store.send(.onAppear)
|
||
}
|
||
// .onReceive(store.publisher(for: \.moment)) { moment in
|
||
// // 监听动态状态变化
|
||
// }
|
||
.fullScreenCover(isPresented: Binding(
|
||
get: { store.showImagePreview },
|
||
set: { _ in store.send(.hideImagePreview) }
|
||
)) {
|
||
ImagePreviewPager(
|
||
images: store.selectedImages,
|
||
currentIndex: Binding(
|
||
get: { store.selectedImageIndex },
|
||
set: { newIndex in
|
||
store.send(.showImagePreview(store.selectedImages, newIndex))
|
||
}
|
||
),
|
||
onClose: {
|
||
store.send(.imagePreviewDismissed)
|
||
}
|
||
)
|
||
}
|
||
}
|
||
|
||
// 判断是否为当前用户的动态
|
||
private var isCurrentUserDynamic: Bool {
|
||
// 暂时返回false,避免异步调用问题
|
||
// TODO: 实现异步获取用户ID的逻辑
|
||
return false
|
||
}
|
||
}
|
||
|
||
//#Preview {
|
||
// DetailView(
|
||
// store: Store(
|
||
// initialState: DetailFeature.State(
|
||
// moment: MomentsInfo(
|
||
// dynamicId: 1,
|
||
// uid: 123,
|
||
// nick: "Test User",
|
||
// avatar: "https://example.com/avatar.jpg",
|
||
// type: 1,
|
||
// content: "This is a test dynamic content",
|
||
// publishTime: Int(Date().timeIntervalSince1970 * 1000),
|
||
// likeCount: 10,
|
||
// isLike: false,
|
||
// worldId: 1,
|
||
// dynamicResList: [
|
||
// MomentsPicture(
|
||
// id: 1,
|
||
// resUrl: "https://example.com/image1.jpg",
|
||
// format: "jpg",
|
||
// width: 800,
|
||
// height: 600,
|
||
// resDuration: nil
|
||
// )
|
||
// ]
|
||
// )
|
||
// )
|
||
// ) {
|
||
// DetailFeature()
|
||
// }
|
||
// )
|
||
//}
|