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