secretive/Secretive/ContentView.swift

66 lines
2.3 KiB
Swift
Raw Normal View History

2020-02-19 03:36:41 +00:00
import SwiftUI
2020-02-19 04:52:00 +00:00
import SecretKit
struct ContentView: View {
2020-03-07 23:20:59 +00:00
@ObservedObject var secureEnclave: SecureEnclave.Store
@ObservedObject var smartCard: SmartCard.Store
@State var active: Data?
@State var showingDeletion = false
@State var deletingSecret: SecureEnclave.Secret?
2020-02-19 03:36:41 +00:00
var body: some View {
2020-03-04 07:14:38 +00:00
NavigationView {
2020-03-07 21:43:57 +00:00
List(selection: $active) {
2020-03-07 23:42:40 +00:00
if secureEnclave.isAvailable {
Section(header: Text(secureEnclave.name)) {
ForEach(secureEnclave.secrets) { secret in
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: self.$active) {
Text(secret.name)
}.contextMenu {
Button(action: { self.delete(secret: secret) }) {
Text("Delete")
}
2020-03-04 07:14:38 +00:00
}
}
}
2020-02-19 04:52:00 +00:00
}
2020-03-07 23:42:40 +00:00
if smartCard.isAvailable {
Section(header: Text(smartCard.name)) {
ForEach(smartCard.secrets) { secret in
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: self.$active) {
Text(secret.name)
}
2020-03-07 23:20:59 +00:00
}
}
}
2020-03-07 06:21:10 +00:00
}.onAppear {
2020-03-07 23:20:59 +00:00
self.active = self.secureEnclave.secrets.first?.id ?? self.smartCard.secrets.first?.id
2020-02-19 04:52:00 +00:00
}
2020-03-04 07:14:38 +00:00
.listStyle(SidebarListStyle())
.frame(minWidth: 100, idealWidth: 240)
2020-03-07 06:21:10 +00:00
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.sheet(isPresented: $showingDeletion) {
2020-03-07 23:20:59 +00:00
DeleteSecretView(secret: self.deletingSecret!, store: self.secureEnclave) {
self.showingDeletion = false
}
}
2020-02-19 03:36:41 +00:00
}
func delete(secret: SecureEnclave.Secret) {
deletingSecret = secret
showingDeletion = true
2020-03-04 07:14:38 +00:00
}
2020-03-04 07:14:38 +00:00
}
2020-03-06 07:48:24 +00:00
//
//struct ContentView_Previews: PreviewProvider {
// static var previews: some View {
// ContentView(store: Preview.Store(numberOfRandomSecrets: 10))
// }
//}