Skip to content

Commit d95a280

Browse files
committed
Migrate HostApp to latest TCA
1 parent 6b5ac69 commit d95a280

File tree

11 files changed

+897
-817
lines changed

11 files changed

+897
-817
lines changed

Core/Sources/HostApp/AccountSettings/APIKeyManagement/APIKeyManagementView.swift

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ struct APIKeyManagementView: View {
2929
.buttonStyle(.plain)
3030
}
3131
.background(Color(nsColor: .separatorColor))
32-
32+
3333
List {
34-
WithPerceptionTracking {
35-
ForEach(store.availableAPIKeyNames, id: \.self) { name in
34+
ForEach(store.availableAPIKeyNames, id: \.self) { name in
35+
WithPerceptionTracking {
3636
HStack {
3737
Text(name)
3838
.contextMenu {
@@ -41,7 +41,7 @@ struct APIKeyManagementView: View {
4141
}
4242
}
4343
Spacer()
44-
44+
4545
Button(action: {
4646
store.send(.deleteButtonClicked(name: name))
4747
}) {
@@ -51,26 +51,24 @@ struct APIKeyManagementView: View {
5151
.buttonStyle(.plain)
5252
}
5353
}
54-
.modify { view in
55-
if #available(macOS 13.0, *) {
56-
view.listRowSeparator(.hidden).listSectionSeparator(.hidden)
57-
} else {
58-
view
59-
}
54+
}
55+
.modify { view in
56+
if #available(macOS 13.0, *) {
57+
view.listRowSeparator(.hidden).listSectionSeparator(.hidden)
58+
} else {
59+
view
6060
}
6161
}
6262
}
6363
.removeBackground()
6464
.overlay {
65-
WithPerceptionTracking {
66-
if store.availableAPIKeyNames.isEmpty {
67-
Text("""
65+
if store.availableAPIKeyNames.isEmpty {
66+
Text("""
6867
Empty
6968
Add a new key by clicking the add button
7069
""")
71-
.multilineTextAlignment(.center)
72-
.padding()
73-
}
70+
.multilineTextAlignment(.center)
71+
.padding()
7472
}
7573
}
7674
}
@@ -95,29 +93,30 @@ struct APIKeySubmissionView: View {
9593
@Perception.Bindable var store: StoreOf<APIKeySubmission>
9694

9795
var body: some View {
98-
ScrollView {
99-
VStack(spacing: 0) {
100-
Form {
101-
WithPerceptionTracking {
96+
WithPerceptionTracking {
97+
ScrollView {
98+
VStack(spacing: 0) {
99+
Form {
102100
TextField("Name", text: $store.name)
103101
SecureField("Key", text: $store.key)
104102
}
105-
}.padding()
103+
.padding()
106104

107-
Divider()
105+
Divider()
108106

109-
HStack {
110-
Spacer()
107+
HStack {
108+
Spacer()
111109

112-
Button("Cancel") { store.send(.cancelButtonClicked) }
113-
.keyboardShortcut(.cancelAction)
110+
Button("Cancel") { store.send(.cancelButtonClicked) }
111+
.keyboardShortcut(.cancelAction)
114112

115-
Button("Save", action: { store.send(.saveButtonClicked) })
116-
.keyboardShortcut(.defaultAction)
117-
}.padding()
113+
Button("Save", action: { store.send(.saveButtonClicked) })
114+
.keyboardShortcut(.defaultAction)
115+
}.padding()
116+
}
118117
}
118+
.textFieldStyle(.roundedBorder)
119119
}
120-
.textFieldStyle(.roundedBorder)
121120
}
122121
}
123122

Core/Sources/HostApp/AccountSettings/APIKeyManagement/APIKeyPicker.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ struct APIKeyPicker: View {
1414
if store.availableAPIKeyNames.isEmpty {
1515
Text("No API key found, please add a new one →")
1616
}
17-
17+
1818
if !store.availableAPIKeyNames.contains(store.apiKeyName),
19-
!store.apiKeyName.isEmpty {
19+
!store.apiKeyName.isEmpty
20+
{
2021
Text("Key not found: \(store.apiKeyName)")
2122
.tag(store.apiKeyName)
2223
}
23-
24+
2425
ForEach(store.availableAPIKeyNames, id: \.self) { name in
2526
Text(name).tag(name)
2627
}
@@ -33,14 +34,16 @@ struct APIKeyPicker: View {
3334
Text(Image(systemName: "key"))
3435
}
3536
}.sheet(isPresented: $store.isAPIKeyManagementPresented) {
36-
APIKeyManagementView(store: store.scope(
37-
state: \.apiKeyManagement,
38-
action: \.apiKeyManagement
39-
))
37+
WithPerceptionTracking {
38+
APIKeyManagementView(store: store.scope(
39+
state: \.apiKeyManagement,
40+
action: \.apiKeyManagement
41+
))
42+
}
43+
}
44+
.onAppear {
45+
store.send(.appear)
4046
}
41-
}
42-
.onAppear {
43-
store.send(.appear)
4447
}
4548
}
4649
}

0 commit comments

Comments
 (0)