From 6584fc4f3dccdac06dfc98e0b4d6bd2860624072 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Wed, 11 Mar 2020 01:53:31 -0700 Subject: [PATCH] Add default selections (fixes #32) --- Secretive/ContentView.swift | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Secretive/ContentView.swift b/Secretive/ContentView.swift index 9d6159b..66ba0f7 100644 --- a/Secretive/ContentView.swift +++ b/Secretive/ContentView.swift @@ -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 {