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

View File

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