Add default selections (fixes #32)

This commit is contained in:
Max Goedjen 2020-03-11 01:53:31 -07:00
parent 07ceffb789
commit 6584fc4f3d
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8

View File

@ -17,11 +17,11 @@ struct ContentView: View {
Section(header: Text(store.name)) {
if store.secrets.isEmpty {
if store is AnySecretStoreModifiable {
NavigationLink(destination: EmptyStoreModifiableView()) {
NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: self.$active) {
Text("No Secrets")
}
} else {
NavigationLink(destination: EmptyStoreView()) {
NavigationLink(destination: EmptyStoreView(), tag: Constants.emptyStoreTag, selection: self.$active) {
Text("No Secrets")
}
}
@ -42,7 +42,13 @@ struct ContentView: View {
}
}
}.onAppear {
self.active = self.storeList.stores.compactMap { $0.secrets.first }.first?.id
let fallback: AnyHashable
if self.storeList.modifiableStore?.isAvailable ?? false {
fallback = Constants.emptyStoreModifiableTag
} else {
fallback = Constants.emptyStoreTag
}
self.active = self.storeList.stores.compactMap { $0.secrets.first }.first?.id ?? fallback
}
.listStyle(SidebarListStyle())
.frame(minWidth: 100, idealWidth: 240)
@ -66,6 +72,15 @@ struct ContentView: View {
}
extension ContentView {
enum Constants {
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {