secretive/Sources/Secretive/Views/DeleteSecretView.swift

58 lines
1.7 KiB
Swift
Raw Permalink Normal View History

import SwiftUI
import SecretKit
2020-03-09 03:03:40 +00:00
struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
2020-09-22 06:12:50 +00:00
2020-03-09 03:03:40 +00:00
@ObservedObject var store: StoreType
2020-09-22 06:12:50 +00:00
let secret: StoreType.SecretType
var dismissalBlock: (Bool) -> ()
@State private var confirm = ""
var body: some View {
VStack {
HStack {
Image(nsImage: NSApplication.shared.applicationIconImage)
.resizable()
.frame(width: 64, height: 64)
.padding()
VStack {
HStack {
Text("Delete \(secret.name)?").bold()
Spacer()
}
HStack {
Text("If you delete \(secret.name), you will not be able to recover it. Type \"\(secret.name)\" to confirm.")
Spacer()
}
HStack {
Text("Confirm Name:")
TextField(secret.name, text: $confirm)
}
}
}
HStack {
Spacer()
2022-06-08 05:02:49 +00:00
Button("Delete", action: mainActorWrapped(delete))
2020-09-22 06:12:50 +00:00
.disabled(confirm != secret.name)
.keyboardShortcut(.delete)
Button("Don't Delete") {
dismissalBlock(false)
}
2020-09-22 06:12:50 +00:00
.keyboardShortcut(.cancelAction)
}
2020-09-22 06:12:50 +00:00
}
.padding()
2020-07-04 23:25:14 +00:00
.frame(minWidth: 400)
.onExitCommand {
dismissalBlock(false)
}
}
func delete() {
try! store.delete(secret: secret)
2020-09-22 06:12:50 +00:00
dismissalBlock(true)
}
2020-09-22 06:12:50 +00:00
}