secretive/Secretive/ContentView.swift

55 lines
1.7 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 {
@ObservedObject var store: SecureEnclave.Store
@State var active: SecureEnclave.Secret?
@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:11:18 +00:00
List(selection: self.$active) {
2020-03-04 07:14:38 +00:00
Section(header: Text(store.name)) {
ForEach(store.secrets) { secret in
2020-03-07 06:21:10 +00:00
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret, selection: self.$active) {
2020-03-04 07:14:38 +00:00
Text(secret.name)
}.contextMenu {
Button(action: { self.delete(secret: secret) }) {
Text("Delete")
}
}
2020-03-07 21:11:18 +00:00
.tag(secret)
2020-03-04 07:14:38 +00:00
}
2020-02-19 04:52:00 +00:00
}
2020-03-07 06:21:10 +00:00
}.onAppear {
self.active = self.store.secrets.first
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) {
DeleteSecretView(secret: self.deletingSecret!, store: self.store) {
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))
// }
//}