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 {
|
2021-12-15 05:03:42 +00:00
|
|
|
Image(nsImage: NSApplication.shared.applicationIconImage)
|
2020-03-07 08:13:56 +00:00
|
|
|
.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()
|
2022-06-08 05:02:49 +00:00
|
|
|
Button("Delete", action: mainActorWrapped(delete))
|
2020-09-22 06:12:50 +00:00
|
|
|
.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
|
|
|
}
|