Add rollback for failed dictionary operations
This commit is contained in:
parent
7beb63e3c6
commit
bf3c035e58
@ -158,6 +158,8 @@ struct VocabularyView: View {
|
||||
do {
|
||||
try modelContext.save()
|
||||
} catch {
|
||||
// Rollback the insert to maintain UI consistency
|
||||
modelContext.delete(newWord)
|
||||
alertMessage = "Failed to add word: \(error.localizedDescription)"
|
||||
showAlert = true
|
||||
}
|
||||
@ -169,6 +171,8 @@ struct VocabularyView: View {
|
||||
do {
|
||||
try modelContext.save()
|
||||
} catch {
|
||||
// Rollback the delete to restore UI consistency
|
||||
modelContext.rollback()
|
||||
alertMessage = "Failed to remove word: \(error.localizedDescription)"
|
||||
showAlert = true
|
||||
}
|
||||
|
||||
@ -227,6 +227,8 @@ struct WordReplacementView: View {
|
||||
originalWord = ""
|
||||
replacementWord = ""
|
||||
} catch {
|
||||
// Rollback the insert to maintain UI consistency
|
||||
modelContext.delete(newReplacement)
|
||||
alertMessage = "Failed to add replacement: \(error.localizedDescription)"
|
||||
showAlert = true
|
||||
}
|
||||
@ -238,6 +240,8 @@ struct WordReplacementView: View {
|
||||
do {
|
||||
try modelContext.save()
|
||||
} catch {
|
||||
// Rollback the delete to restore UI consistency
|
||||
modelContext.rollback()
|
||||
alertMessage = "Failed to remove replacement: \(error.localizedDescription)"
|
||||
showAlert = true
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user