PostDetailView.swift (2512B)
1 import RadrootsKit 2 import SwiftUI 3 4 struct PostDetailView: View { 5 @EnvironmentObject private var app: AppState 6 let post: NostrPostEventMetadata 7 @State private var showCopied = false 8 9 var body: some View { 10 List { 11 Section("Content") { 12 Text(post.post.content) 13 .frame(maxWidth: .infinity, alignment: .leading) 14 .textSelection(.enabled) 15 } 16 17 Section("Event") { 18 CopyRow(title: "Author", value: post.author) { showCopied = true } 19 CopyRow(title: "Event ID", value: post.id) { showCopied = true } 20 21 LabeledContent("Published") { 22 VStack(alignment: .trailing, spacing: 2) { 23 Text(absoluteDate) 24 Text(relativeDate) 25 .foregroundStyle(.secondary) 26 .font(.footnote) 27 } 28 } 29 } 30 } 31 .listStyle(.insetGrouped) 32 .inlineNavigationTitle("Post") 33 .toolbar { 34 ToolbarItem(placement: .topBarTrailing) { 35 if let shareRequest = try? app.publicPostShareRequest(content: post.post.content), 36 let shareLink = try? RadrootsSharePresentationLink(request: shareRequest, label: { 37 Image(systemName: "square.and.arrow.up") 38 }) { 39 shareLink 40 .accessibilityIdentifier("field_ios.post.share") 41 } else { 42 Button {} label: { 43 Image(systemName: "square.and.arrow.up") 44 } 45 .disabled(true) 46 .accessibilityIdentifier("field_ios.post.share_unavailable") 47 } 48 } 49 } 50 .toast(isPresented: $showCopied) { 51 Text("Copied") 52 .padding(.horizontal, 12) 53 .padding(.vertical, 8) 54 .background(.thinMaterial, in: Capsule()) 55 } 56 } 57 58 private var absoluteDate: String { 59 let d = Date(timeIntervalSince1970: TimeInterval(post.publishedAt)) 60 return d.formatted(date: .abbreviated, time: .shortened) 61 } 62 63 private var relativeDate: String { 64 let d = Date(timeIntervalSince1970: TimeInterval(post.publishedAt)) 65 let f = RelativeDateTimeFormatter() 66 f.unitsStyle = .full 67 return f.localizedString(for: d, relativeTo: Date()) 68 } 69 }