secretive/Secretive/DeleteSecretView.swift

59 lines
1.7 KiB
Swift

import SwiftUI
import SecretKit
struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
let secret: StoreType.SecretType
@ObservedObject var store: StoreType
@State var confirm = ""
fileprivate var dismissalBlock: () -> ()
init(secret: StoreType.SecretType, store: StoreType, dismissalBlock: @escaping () -> ()) {
self.secret = secret
self.store = store
self.dismissalBlock = dismissalBlock
}
var body: some View {
VStack {
HStack {
Image(nsImage: NSApp.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)
}
}
.onExitCommand(perform: dismissalBlock)
}
HStack {
Spacer()
Button(action: delete) {
Text("Delete")
}.disabled(confirm != secret.name)
Button(action: dismissalBlock) {
Text("Don't Delete")
}
}
}.padding()
}
func delete() {
try! store.delete(secret: secret)
dismissalBlock()
}
}