5
5
// Description:
6
6
// A SwiftUI form for adjusting chat settings (provider, model, API key, etc.),
7
7
// with dynamic fetching **only** for OpenAI. Anthropic/GitHub use fallback models.
8
+ // Now includes an About link and a confirmation before clearing history.
8
9
//
9
10
10
11
import SwiftUI
@@ -36,7 +37,10 @@ struct SettingsView: View {
36
37
37
38
/// Toggles the share sheet for exporting chat history.
38
39
@State private var isShowingShareSheet = false
39
-
40
+
41
+ /// Toggles the confirmation alert before clearing history.
42
+ @State private var isShowingClearConfirmation = false
43
+
40
44
/// Optional callback to clear messages (e.g., “Clear Conversation History”).
41
45
var clearMessages : ( ( ) -> Void ) ? = nil
42
46
@@ -53,6 +57,8 @@ struct SettingsView: View {
53
57
voiceSection
54
58
themeSection
55
59
exportSection
60
+ exportMemoriesSection
61
+ aboutSection
56
62
clearHistorySection
57
63
}
58
64
. navigationTitle ( " Settings " )
@@ -63,6 +69,15 @@ struct SettingsView: View {
63
69
applicationActivities: nil
64
70
)
65
71
}
72
+ . alert (
73
+ " Are you sure you want to clear all chat history? " ,
74
+ isPresented: $isShowingClearConfirmation
75
+ ) {
76
+ Button ( " Clear " , role: . destructive) {
77
+ clearMessages ? ( )
78
+ }
79
+ Button ( " Cancel " , role: . cancel) { }
80
+ }
66
81
. onAppear {
67
82
// Load system voices if needed
68
83
systemVoices = VoiceHelper . getAvailableVoices ( )
@@ -84,7 +99,6 @@ extension SettingsView {
84
99
}
85
100
}
86
101
. pickerStyle ( . segmented)
87
- // Updated onChange in iOS 17
88
102
. onChange ( of: chatViewModel. appSettings. selectedProvider) { oldProvider, newProvider in
89
103
Task {
90
104
// 1) Fetch or apply fallback models
@@ -101,7 +115,7 @@ extension SettingsView {
101
115
chatViewModel. appSettings. selectedModelId = newProvider. defaultModel. id
102
116
}
103
117
104
- // 3) IMPORTANT: Re-init chat service so we actually switch providers now
118
+ // 3) Re-init chat service so the switch happens now
105
119
chatViewModel. initializeChatService ( with: chatViewModel. appSettings)
106
120
107
121
// 4) Persist
@@ -159,14 +173,13 @@ extension SettingsView {
159
173
SecureField ( " OpenAI API Key " , text: $chatViewModel. appSettings. openAIKey)
160
174
. textInputAutocapitalization ( . never)
161
175
. autocorrectionDisabled ( )
162
- // iOS 17 two-parameter onChange
163
176
. onChange ( of: chatViewModel. appSettings. openAIKey) { oldValue, newValue in
164
177
Task {
165
178
await chatViewModel. saveSettings ( )
166
179
print ( " [SettingsView] OpenAI key changed -> saved. " )
167
180
}
168
181
}
169
-
182
+
170
183
case . anthropic:
171
184
SecureField ( " Anthropic API Key " , text: $chatViewModel. appSettings. anthropicKey)
172
185
. textInputAutocapitalization ( . never)
@@ -262,11 +275,36 @@ extension SettingsView {
262
275
}
263
276
}
264
277
278
+ private var exportMemoriesSection : some View {
279
+ Section ( header: Text ( " Export Memories " ) ,
280
+ footer: Text ( " Exports your Memories.json content as a separate JSON file. " ) ) {
281
+ Button ( " Export Memories to JSON " ) {
282
+ if let fileURL = chatViewModel. memoryStore. exportMemoriesAsJSONFile ( ) {
283
+ shareSheetItems = [ fileURL]
284
+ isShowingShareSheet = true
285
+ } else {
286
+ print ( " Failed to export memories as JSON. " )
287
+ }
288
+ }
289
+ }
290
+ }
291
+
292
+ // MARK: About
293
+ private var aboutSection : some View {
294
+ Section ( header: Text ( " About " ) ) {
295
+ NavigationLink ( " About Ophelia " ) {
296
+ // Ensure you have an AboutView (or rename to your custom view):
297
+ AboutView ( )
298
+ }
299
+ }
300
+ }
301
+
265
302
// MARK: Clear History
266
303
private var clearHistorySection : some View {
267
304
Section {
305
+ // Tapping this triggers an alert confirmation
268
306
Button ( role: . destructive) {
269
- clearMessages ? ( )
307
+ isShowingClearConfirmation = true
270
308
} label: {
271
309
Text ( " Clear Conversation History " )
272
310
}
0 commit comments