IceCubes/IceCubesApp/App/Report/ReportView.swift

77 lines
2.1 KiB
Swift
Raw Normal View History

2023-02-13 21:12:18 +01:00
import DesignSystem
2023-02-18 07:26:48 +01:00
import Env
import Models
2023-02-13 21:12:18 +01:00
import Network
2023-02-18 07:26:48 +01:00
import Status
import SwiftUI
2023-02-13 21:12:18 +01:00
public struct ReportView: View {
@Environment(\.dismiss) private var dismiss
2023-02-18 07:26:48 +01:00
2023-02-13 21:12:18 +01:00
@EnvironmentObject private var theme: Theme
@EnvironmentObject private var client: Client
2023-02-18 07:26:48 +01:00
2023-02-13 21:12:18 +01:00
let status: Status
@State private var commentText: String = ""
@State private var isSendingReport: Bool = false
2023-02-18 07:26:48 +01:00
2023-02-13 21:12:18 +01:00
struct ReportSent: Decodable {
2023-02-18 07:26:48 +01:00
let id: String
2023-02-13 21:12:18 +01:00
}
2023-02-18 07:26:48 +01:00
2023-02-13 21:12:18 +01:00
public var body: some View {
NavigationStack {
Form {
Section {
TextField("report.comment.placeholder",
text: $commentText,
axis: .vertical)
}
.listRowBackground(theme.primaryBackgroundColor)
2023-02-18 07:26:48 +01:00
StatusEmbeddedView(status: status, client: .init(server: ""), routerPath: RouterPath())
2023-02-13 21:12:18 +01:00
.allowsHitTesting(false)
.listRowBackground(theme.primaryBackgroundColor)
}
.navigationTitle("report.title")
.navigationBarTitleDisplayMode(.inline)
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
.scrollDismissesKeyboard(.immediately)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
isSendingReport = true
Task {
do {
let _: ReportSent =
2023-02-18 07:26:48 +01:00
try await client.post(endpoint: Statuses.report(accountId: status.account.id,
statusId: status.id,
comment: commentText))
2023-02-13 21:12:18 +01:00
dismiss()
isSendingReport = false
} catch {
isSendingReport = false
}
}
} label: {
if isSendingReport {
ProgressView()
} else {
Text("report.action.send")
}
}
}
2023-02-18 07:26:48 +01:00
2023-02-13 21:12:18 +01:00
ToolbarItem(placement: .navigationBarLeading) {
Button {
dismiss()
} label: {
Text("action.cancel")
}
}
}
}
}
}