1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import SwiftUI
struct PostDivider: View {
@Environment(\.displayScale) private var displayScale
var body: some View {
Rectangle()
.fill(Color(uiColor: .separator))
.frame(height: 1 / displayScale)
.accessibilityHidden(true)
}
}
struct RepostAttributionRow: View {
@AppStorage("handlesOnly") private var handlesOnly = false
@Environment(AppModel.self) private var model
let postID: String
let author: Post.Author
let openProfile: () -> Void
var body: some View {
if !model.isHidden(author.id), model.contentDecision(author: author)?.action == .allow {
Button(action: openProfile) {
Label(
"Reposted by \(DisplayPreferences(handlesOnly: handlesOnly).name(author))",
systemImage: "arrow.2.squarepath"
)
.appFont(.subheadline, weight: .medium)
.foregroundStyle(AppPalette.reply)
}
.buttonStyle(.plain)
.accessibilityIdentifier("repostAttribution-\(postID)")
}
}
}
struct PostTimestamp: View {
let date: Date
var body: some View {
TimelineView(.periodic(from: .now, by: 60)) { context in
Text(PostElapsedTime.text(since: date, now: context.date))
}
.appFont(.caption)
.foregroundStyle(Color(uiColor: .secondaryLabel))
}
}
#if DEBUG && !SHARE_EXTENSION
#Preview("Post metadata") {
PreviewHost { _ in
VStack(alignment: .leading, spacing: 16) {
RepostAttributionRow(postID: "post-1", author: PreviewContent.author, openProfile: {})
PostDivider()
PostTimestamp(date: PreviewContent.date)
}
.padding()
}
}
#endif