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_confirmation_title_\(secret.name)").bold()
Spacer()
}
HStack {
Text("delete_confirmation_description_\(secret.name)_\(secret.name)")
Spacer()
}
HStack {
Text("delete_confirmation_confirm_name_label")
TextField(secret.name, text: $confirm)
}
}
}
HStack {
Spacer()
Button("delete_confirmation_delete_button", action: delete)
2020-09-22 06:12:50 +00:00
.disabled(confirm != secret.name)
Button("delete_confirmation_cancel_button") {
2020-09-22 06:12:50 +00:00
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
}