Files
e-party-iOS/yana/Views/DetailView.swift
edwinQQQ de2f05f545 feat: 新增动态点赞与删除功能
- 在APIEndpoints中新增动态点赞和删除端点。
- 实现LikeDynamicRequest和DeleteDynamicRequest结构体,支持动态点赞和删除请求。
- 在DetailFeature中添加点赞和删除动态的逻辑,提升用户交互体验。
- 更新FeedListFeature以支持动态详情视图的展示,增强用户体验。
- 新增DetailView以展示动态详情,包含点赞和删除功能。
2025-07-28 11:23:34 +08:00

122 lines
4.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 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) {
// uiduid
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()
// }
// )
//}