56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
import SwiftUI
|
|
import ProxyCore
|
|
|
|
struct CURLImportView: View {
|
|
let onImport: (ParsedCURLRequest) -> Void
|
|
|
|
@State private var curlText = ""
|
|
@State private var errorMessage: String?
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text("Paste a cURL command to import as a request.")
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
|
|
TextEditor(text: $curlText)
|
|
.font(.system(.caption, design: .monospaced))
|
|
.frame(minHeight: 200)
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.stroke(Color(.systemGray4))
|
|
)
|
|
|
|
if let errorMessage {
|
|
Text(errorMessage)
|
|
.font(.caption)
|
|
.foregroundStyle(.red)
|
|
}
|
|
|
|
Button("Import") {
|
|
if let parsed = CURLParser.parse(curlText) {
|
|
onImport(parsed)
|
|
} else {
|
|
errorMessage = "Invalid cURL command. Make sure it starts with 'curl'."
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(curlText.isEmpty)
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
.navigationTitle("Import cURL")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Cancel") { dismiss() }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|