Select default

This commit is contained in:
Max Goedjen 2020-03-06 22:21:10 -08:00
parent f60e7c79f2
commit b1091904ed
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
1 changed files with 7 additions and 2 deletions

View File

@ -4,13 +4,14 @@ import SecretKit
struct ContentView<StoreType: SecretStore>: View { struct ContentView<StoreType: SecretStore>: View {
@ObservedObject var store: StoreType @ObservedObject var store: StoreType
@State var active: StoreType.SecretType?
var body: some View { var body: some View {
NavigationView { NavigationView {
List { List {
Section(header: Text(store.name)) { Section(header: Text(store.name)) {
ForEach(store.secrets) { secret in ForEach(store.secrets) { secret in
NavigationLink(destination: SecretDetailView(secret: secret)) { NavigationLink(destination: SecretDetailView(secret: secret), tag: secret, selection: self.$active) {
Text(secret.name) Text(secret.name)
}.contextMenu { }.contextMenu {
Button(action: { self.delete(secret: secret) }) { Button(action: { self.delete(secret: secret) }) {
@ -19,10 +20,14 @@ struct ContentView<StoreType: SecretStore>: View {
} }
} }
} }
}.onAppear {
self.active = self.store.secrets.first
} }
.listStyle(SidebarListStyle()) .listStyle(SidebarListStyle())
.frame(minWidth: 100, idealWidth: 240) .frame(minWidth: 100, idealWidth: 240)
}.navigationViewStyle(DoubleColumnNavigationViewStyle()) }
.navigationViewStyle(DoubleColumnNavigationViewStyle())
} }