Fix cap deletion

This commit is contained in:
Christoph Hagen 2023-10-24 20:59:15 +02:00
parent 403ab1dee5
commit 300c1849fb
2 changed files with 8 additions and 2 deletions

View File

@ -295,7 +295,7 @@ struct ContentView: View {
.alert(Text("Delete cap"), .alert(Text("Delete cap"),
isPresented: $showDeleteCapAlert, isPresented: $showDeleteCapAlert,
actions: { actions: {
Button("Delete", role: .destructive, action: saveNewCapName) Button("Delete", role: .destructive, action: startDeleteCap)
Button("Cancel", role: .cancel, action: {}) Button("Cancel", role: .cancel, action: {})
}, message: { }, message: {
Text("Confirm the deletion of cap \(selectedCapId ?? 0)") Text("Confirm the deletion of cap \(selectedCapId ?? 0)")
@ -420,12 +420,16 @@ struct ContentView: View {
private func startDeleteCap() { private func startDeleteCap() {
guard let cap = selectedCapId else { guard let cap = selectedCapId else {
print("No cap to delete")
return return
} }
Task { Task {
print("Deleting cap \(cap)")
guard await database.delete(cap: cap) else { guard await database.delete(cap: cap) else {
print("Failed to delete cap \(cap)")
return return
} }
print("Deleted cap \(cap)")
} }
} }
} }

View File

@ -800,7 +800,9 @@ final class Database: ObservableObject {
// Delete cached images // Delete cached images
images.removeCachedImages(for: cap) images.removeCachedImages(for: cap)
// Delete cap // Delete cap
caps[cap] = nil DispatchQueue.main.async {
self.caps[cap] = nil
}
log("Deleted cap \(cap)") log("Deleted cap \(cap)")
return true return true
} catch { } catch {