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-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 = ""
|
|
|
|
|
2020-03-07 08:13:56 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2020-09-22 06:12:50 +00:00
|
|
|
Button("Delete", action: delete)
|
|
|
|
.disabled(confirm != secret.name)
|
|
|
|
.keyboardShortcut(.delete)
|
|
|
|
Button("Don't Delete") {
|
|
|
|
dismissalBlock(false)
|
2020-03-07 08:13:56 +00:00
|
|
|
}
|
2020-09-22 06:12:50 +00:00
|
|
|
.keyboardShortcut(.cancelAction)
|
2020-03-07 08:13:56 +00:00
|
|
|
}
|
2020-09-22 06:12:50 +00:00
|
|
|
}
|
|
|
|
.padding()
|
2020-07-04 23:25:14 +00:00
|
|
|
.frame(minWidth: 400)
|
2021-06-01 06:20:38 +00:00
|
|
|
.onExitCommand {
|
|
|
|
dismissalBlock(false)
|
|
|
|
}
|
2020-03-07 08:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func delete() {
|
|
|
|
try! store.delete(secret: secret)
|
2020-09-22 06:12:50 +00:00
|
|
|
dismissalBlock(true)
|
2020-03-07 08:13:56 +00:00
|
|
|
}
|
2020-09-22 06:12:50 +00:00
|
|
|
|
2020-03-07 08:13:56 +00:00
|
|
|
}
|