forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomHeaderSettingsView.swift
More file actions
78 lines (71 loc) · 2.43 KB
/
Copy pathCustomHeaderSettingsView.swift
File metadata and controls
78 lines (71 loc) · 2.43 KB
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
import AIModel
import Foundation
import SwiftUI
struct CustomHeaderSettingsView: View {
@Binding var headers: [ChatModel.Info.CustomHeaderInfo.HeaderField]
@Environment(\.dismiss) var dismiss
@State private var newKey = ""
@State private var newValue = ""
var body: some View {
VStack {
List {
ForEach(headers.indices, id: \.self) { index in
HStack {
TextField("Key", text: Binding(
get: { headers[index].key },
set: { newKey in
headers[index].key = newKey
}
))
TextField("Value", text: Binding(
get: { headers[index].value },
set: { headers[index].value = $0 }
))
Button(action: {
headers.remove(at: index)
}) {
Image(systemName: "trash")
.foregroundColor(.red)
}
}
}
HStack {
TextField("New Key", text: $newKey)
TextField("New Value", text: $newValue)
Button(action: {
if !newKey.isEmpty {
headers.append(ChatModel.Info.CustomHeaderInfo.HeaderField(
key: newKey,
value: newValue
))
newKey = ""
newValue = ""
}
}) {
Image(systemName: "plus.circle.fill")
.foregroundColor(.green)
}
}
}
HStack {
Spacer()
Button("Done") {
dismiss()
}
}.padding()
}
.frame(height: 500)
}
}
#Preview {
struct V: View {
@State var headers: [ChatModel.Info.CustomHeaderInfo.HeaderField] = [
.init(key: "key", value: "value"),
.init(key: "key2", value: "value2"),
]
var body: some View {
CustomHeaderSettingsView(headers: $headers)
}
}
return V()
}