77 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
import SwiftUI
 | 
						|
 | 
						|
struct PostDetailView: View {
 | 
						|
    let postID: UUID
 | 
						|
    @Environment(\.presentationMode) var presentationMode
 | 
						|
    @State private var post: Post? = nil
 | 
						|
 | 
						|
    var body: some View {
 | 
						|
        ZStack {
 | 
						|
            if let post = post {
 | 
						|
                Color.black.ignoresSafeArea()
 | 
						|
 | 
						|
                VStack {
 | 
						|
                    Spacer()
 | 
						|
 | 
						|
                    VStack(alignment: .leading, spacing: 8) {
 | 
						|
                        if let title = post.title {
 | 
						|
                            Text(title)
 | 
						|
                                .font(.title2)
 | 
						|
                                .fontWeight(.bold)
 | 
						|
                                .foregroundColor(.white)
 | 
						|
                        }
 | 
						|
 | 
						|
                        if let desc = post.description {
 | 
						|
                            Text(desc)
 | 
						|
                                .font(.subheadline)
 | 
						|
                                .foregroundColor(Color.white.opacity(0.8))
 | 
						|
                        }
 | 
						|
 | 
						|
                        Text("UUID: \(post.id.uuidString)")
 | 
						|
                            .font(.caption2)
 | 
						|
                            .foregroundColor(Color.white.opacity(0.5))
 | 
						|
 | 
						|
                        HStack(spacing: 12) {
 | 
						|
                            Label("\(post.views)", systemImage: "eye")
 | 
						|
                            Label("\(post.likes)", systemImage: "heart")
 | 
						|
                            Label("\(post.saves)", systemImage: "bookmark")
 | 
						|
                            Label("\(post.commentsCount)", systemImage: "text.bubble")
 | 
						|
                        }
 | 
						|
                        .font(.footnote)
 | 
						|
                        .foregroundColor(Color.white.opacity(0.9))
 | 
						|
                    }
 | 
						|
                    .padding()
 | 
						|
                    .background(Color.black.opacity(0.4))
 | 
						|
                    .cornerRadius(12)
 | 
						|
                    .padding(.horizontal)
 | 
						|
                    .padding(.bottom, 32)
 | 
						|
                }
 | 
						|
 | 
						|
                VStack {
 | 
						|
                    HStack {
 | 
						|
                        Spacer()
 | 
						|
                        Button(action: {
 | 
						|
                            presentationMode.wrappedValue.dismiss()
 | 
						|
                        }) {
 | 
						|
                            Image(systemName: "xmark.circle.fill")
 | 
						|
                                .font(.system(size: 30))
 | 
						|
                                .foregroundColor(.white)
 | 
						|
                                .padding()
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    Spacer()
 | 
						|
                }
 | 
						|
            } else {
 | 
						|
                ProgressView("Загрузка поста…")
 | 
						|
                    .progressViewStyle(CircularProgressViewStyle(tint: .white))
 | 
						|
                    .foregroundColor(.white)
 | 
						|
                    .onAppear {
 | 
						|
                        PostService.shared.fetchPost(by: postID) { result in
 | 
						|
                            self.post = result
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |