Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions DBDebugToolkit/Classes/Swift/Views/RequestDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,23 @@ private extension RequestDetails {
rowView(title: key, subtitle: value)
}
}
CopyButton {
headerFields.keys.sorted().reduce("") { partialResult, key in
if let value = headerFields[key] {
return partialResult + "\(key): \(value)\n"
}
return partialResult
}
}
}
}

Section(header: Text("Body")) {
rowView(title: "Body length", subtitle: "\(model.requestBodyLength)")
NavigationLink("Body preview", destination: RequestBodyPreview(model: model, mode: .request))
CopyButton {
String(data: await model.readRequestBody() ?? Data(), encoding: .utf8)
}
}
}

Expand All @@ -74,12 +85,23 @@ private extension RequestDetails {
rowView(title: key, subtitle: value)
}
}
CopyButton {
headerFields.keys.sorted().reduce("") { partialResult, key in
if let value = headerFields[key] {
return partialResult + "\(key): \(value)\n"
}
return partialResult
}
}
}
}

Section(header: Text("Body")) {
rowView(title: "Body length", subtitle: "\(model.responseBodyLength)")
NavigationLink("Body preview", destination: RequestBodyPreview(model: model, mode: .response))
CopyButton {
String(data: await model.readResponseBody() ?? Data(), encoding: .utf8)
}
}
}

Expand All @@ -92,3 +114,33 @@ private extension RequestDetails {
}
}
}


private struct CopyButton: View {
let data: () async -> String?
@State private var showCheckmark = false

var body: some View {
Button {
Task {
if let text = await data() {
UIPasteboard.general.string = text
withAnimation(.easeInOut(duration: 0.3)) {
showCheckmark = true
}
try? await Task.sleep(nanoseconds: 1_500_000_000)
withAnimation(.easeInOut(duration: 0.3)) {
showCheckmark = false
}
}
}
} label: {
HStack {
Text("Copy")
Image(systemName: showCheckmark ? "checkmark.circle.fill" : "doc.on.doc")
.foregroundColor(showCheckmark ? .green : .accentColor)
.animation(.easeInOut(duration: 0.3), value: showCheckmark)
}
}
}
}