IceCubes/IceCubesApp/App/Report/ReportView.swift

73 lines
2.0 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
2024-01-06 19:27:26 +01:00
import StatusKit
2023-02-18 07:26:48 +01:00
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-09-18 21:03:52 +02:00
@Environment(Theme.self) private var theme
@Environment(Client.self) private var 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)
#if !os(visionOS)
2024-02-14 12:48:14 +01:00
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
.scrollDismissesKeyboard(.immediately)
#endif
2024-02-14 12:48:14 +01:00
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
isSendingReport = true
Task {
do {
let _: ReportSent =
try await client.post(endpoint: Statuses.report(accountId: status.account.id,
statusId: status.id,
comment: commentText))
dismiss()
isSendingReport = false
} catch {
isSendingReport = false
}
}
} label: {
if isSendingReport {
ProgressView()
} else {
Text("report.action.send")
2023-02-13 21:12:18 +01:00
}
}
}
2023-02-18 07:26:48 +01:00
2024-02-14 12:48:14 +01:00
CancelToolbarItem()
}
2023-02-13 21:12:18 +01:00
}
}
}