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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import SwiftUI
#if DEBUG
#Preview("Report post") {
PreviewHost { _ in
NavigationStack { PostReportView(subject: .post(uri: "post-1", cid: "preview")) }
}
}
#Preview("Report account") {
PreviewHost { _ in
NavigationStack { PostReportView(subject: .account(PreviewContent.author.id)) }
}
}
#endif
struct PostReportView: View {
@Environment(AppModel.self) private var model
@Environment(\.dismiss) private var dismiss
let subject: ReportSubject
@State private var reason = "com.atproto.moderation.defs#reasonSpam"
@State private var reportSent = false
@State private var sending = false
@State private var submissionUnavailable = false
private var isBusy: Bool { sending || model.moderationBusy.contains("report") }
private var isUncertain: Bool { model.uncertainReports.contains(subject.retryKey) }
private var title: String {
switch subject {
case .account: "Report account"
case .post: "Report post"
}
}
var body: some View {
NavigationStack {
Form {
if reportSent {
Section {
Text("The moderation service received your report.").accessibilityIdentifier("reportSent")
}
} else if isUncertain {
Section {
Text("The report result is unknown. Sending it again can create a duplicate report.")
.accessibilityIdentifier("moderationError")
}
} else if let error = model.moderationError {
Section {
Text(error).accessibilityIdentifier("moderationError")
Button("Dismiss error") { model.clearModerationError() }
}
} else if submissionUnavailable {
Section {
Text("The report was not sent. Try again.")
}
}
if !reportSent {
Section("Report reason") {
Picker("Reason", selection: $reason) {
Text("Spam").tag("com.atproto.moderation.defs#reasonSpam")
Text("Harassment").tag("com.atproto.moderation.defs#reasonRude")
Text("Sexual content").tag("com.atproto.moderation.defs#reasonSexual")
Text("Misleading content").tag("com.atproto.moderation.defs#reasonMisleading")
Text("Other").tag("com.atproto.moderation.defs#reasonOther")
}
.disabled(isBusy || isUncertain)
if isBusy {
ProgressView("Sending report")
} else if !isUncertain {
Button("Send report") {
submissionUnavailable = false
sending = true
model.clearModerationError()
Task {
let succeeded = await model.submitReport(subject, reason: reason)
if succeeded {
reportSent = true
} else if model.moderationError == nil && !isUncertain {
submissionUnavailable = true
}
sending = false
}
}
}
}
}
}
.appNavigationTitle(title)
.toolbar { Button("Done") { dismiss() }.disabled(isBusy) }
.interactiveDismissDisabled(isBusy)
.onAppear { model.clearModerationError() }
}
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
}