forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIKeyPicker.swift
More file actions
47 lines (40 loc) · 1.66 KB
/
APIKeyPicker.swift
File metadata and controls
47 lines (40 loc) · 1.66 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
import ComposableArchitecture
import SwiftUI
struct APIKeyPicker: View {
let store: StoreOf<APIKeySelection>
var body: some View {
WithViewStore(store) { viewStore in
HStack {
Picker(
selection: viewStore.$apiKeyName,
content: {
Text("No API Key").tag("")
if viewStore.state.availableAPIKeyNames.isEmpty {
Text("No API key found, please add a new one →")
}
if !viewStore.state.availableAPIKeyNames.contains(viewStore.state.apiKeyName),
!viewStore.state.apiKeyName.isEmpty {
Text("Key not found: \(viewStore.state.apiKeyName)")
.tag(viewStore.state.apiKeyName)
}
ForEach(viewStore.state.availableAPIKeyNames, id: \.self) { name in
Text(name).tag(name)
}
},
label: { Text("API Key") }
)
Button(action: { store.send(.manageAPIKeysButtonClicked) }) {
Text(Image(systemName: "key"))
}
}.sheet(isPresented: viewStore.$isAPIKeyManagementPresented) {
APIKeyManagementView(store: store.scope(
state: \.apiKeyManagement,
action: APIKeySelection.Action.apiKeyManagement
))
}
}
.onAppear {
store.send(.appear)
}
}
}