secretive/Sources/Secretive/Views/DeleteSecretView.swift

57 lines
1.6 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()
2020-09-22 06:12:50 +00:00
Button("Delete", action: delete)
.disabled(confirm != secret.name)
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
}