fix: PersonalDictionaryView preview and AppGroupStore dictionary writes
Use ThemedRoot in preview instead of inaccessible ThemePalette(). Add setPersonalDictionary(_:) for let AppGroupStore bindings; use it from PersonalDictionaryView and DictionaryLearner. Co-authored-by: Rocky <hkgood@users.noreply.github.com>
This commit is contained in:
@@ -144,7 +144,7 @@ final class DictionaryLearner {
|
|||||||
|
|
||||||
if didChange {
|
if didChange {
|
||||||
dictionary.version += 1
|
dictionary.version += 1
|
||||||
store.personalDictionary = dictionary
|
store.setPersonalDictionary(dictionary)
|
||||||
}
|
}
|
||||||
// Suppress the "did not change" path; we still return the
|
// Suppress the "did not change" path; we still return the
|
||||||
// bumped-counts view so the caller can refresh a UI label.
|
// bumped-counts view so the caller can refresh a UI label.
|
||||||
|
|||||||
@@ -224,11 +224,14 @@ struct PersonalDictionaryView: View {
|
|||||||
|
|
||||||
private func persist() {
|
private func persist() {
|
||||||
dictionary.version += 1
|
dictionary.version += 1
|
||||||
store.personalDictionary = dictionary
|
store.setPersonalDictionary(dictionary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
#Preview {
|
#Preview {
|
||||||
PersonalDictionaryView()
|
ThemedRoot {
|
||||||
.environment(\.themePalette, ThemePalette())
|
PersonalDictionaryView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -341,14 +341,18 @@ public struct AppGroupStore: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
do {
|
setPersonalDictionary(newValue)
|
||||||
let data = try JSONEncoder().encode(newValue)
|
}
|
||||||
defaults.set(data, forKey: Key.personalDictionary)
|
}
|
||||||
} catch {
|
|
||||||
#if DEBUG
|
public func setPersonalDictionary(_ dictionary: PersonalDictionary) {
|
||||||
print("⚠️ [AppGroupStore] personalDictionary encode failed: \(error)")
|
do {
|
||||||
#endif
|
let data = try JSONEncoder().encode(dictionary)
|
||||||
}
|
defaults.set(data, forKey: Key.personalDictionary)
|
||||||
|
} catch {
|
||||||
|
#if DEBUG
|
||||||
|
print("⚠️ [AppGroupStore] personalDictionary encode failed: \(error)")
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user