secretive/Secretive/DeleteSecretView.swift

61 lines
1.8 KiB
Swift
Raw Normal View History

import SwiftUI
import SecretKit
2020-03-09 03:03:40 +00:00
struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
2020-03-09 03:03:40 +00:00
let secret: StoreType.SecretType
@ObservedObject var store: StoreType
@State var confirm = ""
2020-03-15 21:03:57 +00:00
fileprivate var dismissalBlock: (Bool) -> ()
2020-03-15 21:03:57 +00:00
init(secret: StoreType.SecretType, store: StoreType, dismissalBlock: @escaping (Bool) -> ()) {
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)
}
}
2020-03-15 21:03:57 +00:00
.onExitCommand {
self.dismissalBlock(false)
}
}
HStack {
Spacer()
Button(action: delete) {
Text("Delete")
}.disabled(confirm != secret.name)
2020-03-15 21:03:57 +00:00
Button(action: { self.dismissalBlock(false) }) {
Text("Don't Delete")
}
}
}.padding()
}
func delete() {
try! store.delete(secret: secret)
2020-03-15 21:03:57 +00:00
self.dismissalBlock(true)
}
}