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