From 794de4e1325bf9854a1f7c1dbcaca450a8fdd7fa Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 13 Sep 2020 23:11:13 -0600 Subject: [PATCH] Break out empty view. --- Secretive/Views/EmptyStoreView.swift | 30 +++++++++++++++++++++++++++- Secretive/Views/StoreListView.swift | 19 +++--------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Secretive/Views/EmptyStoreView.swift b/Secretive/Views/EmptyStoreView.swift index 0f8a6f4..db85890 100644 --- a/Secretive/Views/EmptyStoreView.swift +++ b/Secretive/Views/EmptyStoreView.swift @@ -1,6 +1,34 @@ import SwiftUI +import SecretKit struct EmptyStoreView: View { + + @ObservedObject var store: AnySecretStore + @Binding var activeSecret: AnySecret.ID? + + var body: some View { + if store is AnySecretStoreModifiable { + NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: $activeSecret) { + Text("No Secrets") + } + } else { + NavigationLink(destination: EmptyStoreImmutableView(), tag: Constants.emptyStoreTag, selection: $activeSecret) { + Text("No Secrets") + } + } + } +} + +extension EmptyStoreView { + + enum Constants { + static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag" + static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag" + } + +} + +struct EmptyStoreImmutableView: View { var body: some View { VStack { @@ -48,7 +76,7 @@ struct EmptyStoreModifiableView: View { struct EmptyStoreModifiableView_Previews: PreviewProvider { static var previews: some View { Group { - EmptyStoreView() + EmptyStoreImmutableView() EmptyStoreModifiableView() } } diff --git a/Secretive/Views/StoreListView.swift b/Secretive/Views/StoreListView.swift index 35d87fd..53aae63 100644 --- a/Secretive/Views/StoreListView.swift +++ b/Secretive/Views/StoreListView.swift @@ -15,15 +15,7 @@ struct StoreListView: View { if store.isAvailable { Section(header: Text(store.name)) { if store.secrets.isEmpty { - if store is AnySecretStoreModifiable { - NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: $activeSecret) { - Text("No Secrets") - } - } else { - NavigationLink(destination: EmptyStoreView(), tag: Constants.emptyStoreTag, selection: $activeSecret) { - Text("No Secrets") - } - } + EmptyStoreView(store: store, activeSecret: $activeSecret) } else { SecretListView(store: store, activeSecret: $activeSecret, deletingSecret: $deletingSecret, deletedSecret: { _ in activeSecret = nextDefaultSecret @@ -48,16 +40,11 @@ extension StoreListView { var nextDefaultSecret: AnyHashable? { let fallback: AnyHashable if storeList.modifiableStore?.isAvailable ?? false { - fallback = Constants.emptyStoreModifiableTag + fallback = EmptyStoreView.Constants.emptyStoreModifiableTag } else { - fallback = Constants.emptyStoreTag + fallback = EmptyStoreView.Constants.emptyStoreTag } return storeList.stores.compactMap(\.secrets.first).first?.id ?? fallback } } - -private enum Constants { - static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag" - static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag" -}