@@ -3,7 +3,7 @@ import SwiftUI
33@Observable final class AISettingsViewModel {
44 var usesJetpackAsDefaultAIProviderSource : Bool = false
55 var isEditingApiKey : Bool = false
6- var apiKey : String = " foo "
6+ var apiKey : String = " "
77 var selectedProvider : String = " OpenAI "
88 var selectedModel : String = " gpt-4 "
99
@@ -16,6 +16,7 @@ import SwiftUI
1616
1717 func updateProvider( _ provider: String ) {
1818 // TODO
19+ // Switches between AI providers
1920 }
2021
2122 func clearAPIKey( ) {
@@ -39,9 +40,13 @@ struct AISettingsView: View {
3940 viewModel. usesJetpackAsDefaultAIProviderSource
4041 }
4142
43+ private var fieldOpacity : Double {
44+ aiSettingsDisabled ? 0.5 : 1.0
45+ }
46+
4247 var body : some View {
43- // Enables VM $ Bindables
4448 @Bindable var viewModel = viewModel
49+
4550 VStack ( alignment: . leading) {
4651 if aiSettingsDisabled {
4752 JetpackAsAIDefaultSourceBannerView ( )
@@ -72,7 +77,7 @@ struct AISettingsView: View {
7277 Text ( viewModel. isEditingApiKey ? Localization . save : Localization . edit)
7378 }
7479 . disabled ( aiSettingsDisabled)
75- . opacity ( aiSettingsDisabled ? 0.5 : 1.0 )
80+ . opacity ( fieldOpacity )
7681 }
7782
7883 Text ( Localization . apiKeyDescription)
@@ -83,14 +88,15 @@ struct AISettingsView: View {
8388 Text ( Localization . aiProvider)
8489 . foregroundColor ( . secondary)
8590 Picker ( Localization . selectProvider, selection: $viewModel. selectedProvider) {
91+ // TODO
8692 Text ( Localization . openAI) . tag ( Localization . openAI)
8793 }
8894 . pickerStyle ( MenuPickerStyle ( ) )
8995 . onChange ( of: viewModel. selectedProvider) { _, newValue in
9096 viewModel. updateProvider ( newValue)
9197 }
9298 . disabled ( aiSettingsDisabled)
93- . opacity ( aiSettingsDisabled ? 0.5 : 1.0 )
99+ . opacity ( fieldOpacity )
94100
95101 if viewModel. usesJetpackAsDefaultAIProviderSource {
96102 Image ( systemName: " lock.fill " )
@@ -102,11 +108,11 @@ struct AISettingsView: View {
102108 . foregroundColor ( . secondary)
103109 Picker ( Localization . selectModel, selection: $viewModel. selectedModel) {
104110 // TODO
105- Text ( " Default model " ) . tag ( " model " )
111+ Text ( viewModel . selectedModel ) . tag ( viewModel . selectedModel )
106112 }
107113 . pickerStyle ( MenuPickerStyle ( ) )
108114 . disabled ( aiSettingsDisabled)
109- . opacity ( aiSettingsDisabled ? 0.5 : 1.0 )
115+ . opacity ( fieldOpacity )
110116
111117 if aiSettingsDisabled {
112118 Image ( systemName: " lock.fill " )
@@ -133,17 +139,21 @@ private extension AISettingsView {
133139 . foregroundColor ( . secondary)
134140 . padding ( )
135141 . background (
136- RoundedRectangle ( cornerRadius: 8 )
142+ RoundedRectangle ( cornerRadius: Layout . cornerRadius )
137143 . fill ( Color ( . systemGray6) )
138144 )
139145 . overlay (
140- RoundedRectangle ( cornerRadius: 8 )
146+ RoundedRectangle ( cornerRadius: Layout . cornerRadius )
141147 . stroke ( Color ( . gray) , lineWidth: 1 )
142148 )
143149 }
144150}
145151
146152private extension AISettingsView {
153+ enum Layout {
154+ static let cornerRadius : CGFloat = 8
155+ }
156+
147157 enum Localization {
148158 static let navigationTitle = NSLocalizedString (
149159 " aiSettings.navigationTitle " ,
0 commit comments