secretive/Secretive/ContentView.swift

54 lines
1.6 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
2020-03-07 21:43:57 +00:00
@State var active: SecureEnclave.Secret.ID?
@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-04 07:14:38 +00:00
Section(header: Text(store.name)) {
ForEach(store.secrets) { secret in
2020-03-07 21:43:57 +00:00
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: self.$active) {
2020-03-04 07:14:38 +00:00
Text(secret.name)
}.contextMenu {
Button(action: { self.delete(secret: secret) }) {
Text("Delete")
}
}
}
2020-02-19 04:52:00 +00:00
}
2020-03-07 06:21:10 +00:00
}.onAppear {
2020-03-07 21:43:57 +00:00
self.active = self.store.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) {
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))
// }
//}