secretive/Secretive/Views/CreateSecretView.swift

55 lines
1.5 KiB
Swift
Raw Normal View History

2020-03-04 07:14:38 +00:00
import SwiftUI
import SecretKit
struct CreateSecretView: View {
2020-03-07 08:00:09 +00:00
2020-03-09 03:03:40 +00:00
@ObservedObject var store: AnySecretStoreModifiable
2020-03-07 08:00:09 +00:00
2020-03-04 07:14:38 +00:00
@State var name = ""
@State var requiresAuthentication = true
2020-03-07 08:00:09 +00:00
2020-03-04 07:14:38 +00:00
var dismissalBlock: () -> ()
2020-03-07 08:00:09 +00:00
2020-03-04 07:14:38 +00:00
var body: some View {
2020-03-07 08:00:09 +00:00
VStack {
HStack {
Image(nsImage: NSApp.applicationIconImage)
.resizable()
.frame(width: 64, height: 64)
.padding()
VStack {
HStack {
Text("Create a New Secret").bold()
Spacer()
}
HStack {
Text("Name:")
2020-03-12 05:17:35 +00:00
TextField("Shhhhh", text: $name)
2020-03-07 08:00:09 +00:00
}
HStack {
Toggle(isOn: $requiresAuthentication) {
Text("Requires Authentication (Biometrics or Password)")
}
Spacer()
}
2020-03-04 07:14:38 +00:00
}
2020-03-07 08:00:09 +00:00
.onExitCommand(perform: dismissalBlock)
2020-03-04 07:14:38 +00:00
}
2020-03-07 08:00:09 +00:00
HStack {
Spacer()
Button(action: dismissalBlock) {
Text("Cancel")
2020-03-04 07:14:38 +00:00
}
2020-03-07 08:00:09 +00:00
Button(action: save) {
Text("Create")
}.disabled(name.isEmpty)
2020-03-04 07:14:38 +00:00
}
2020-03-07 08:00:09 +00:00
}.padding()
2020-03-04 07:14:38 +00:00
}
2020-03-07 08:00:09 +00:00
2020-03-04 07:14:38 +00:00
func save() {
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
dismissalBlock()
}
}