mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-19 22:12:26 +00:00
Break out empty view.
This commit is contained in:
parent
cc9a23a3e8
commit
794de4e132
@ -1,7 +1,35 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import SecretKit
|
||||||
|
|
||||||
struct EmptyStoreView: View {
|
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 {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Text("No Secrets").bold()
|
Text("No Secrets").bold()
|
||||||
@ -48,7 +76,7 @@ struct EmptyStoreModifiableView: View {
|
|||||||
struct EmptyStoreModifiableView_Previews: PreviewProvider {
|
struct EmptyStoreModifiableView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
Group {
|
||||||
EmptyStoreView()
|
EmptyStoreImmutableView()
|
||||||
EmptyStoreModifiableView()
|
EmptyStoreModifiableView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,7 @@ struct StoreListView: View {
|
|||||||
if store.isAvailable {
|
if store.isAvailable {
|
||||||
Section(header: Text(store.name)) {
|
Section(header: Text(store.name)) {
|
||||||
if store.secrets.isEmpty {
|
if store.secrets.isEmpty {
|
||||||
if store is AnySecretStoreModifiable {
|
EmptyStoreView(store: store, activeSecret: $activeSecret)
|
||||||
NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: $activeSecret) {
|
|
||||||
Text("No Secrets")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
NavigationLink(destination: EmptyStoreView(), tag: Constants.emptyStoreTag, selection: $activeSecret) {
|
|
||||||
Text("No Secrets")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
SecretListView(store: store, activeSecret: $activeSecret, deletingSecret: $deletingSecret, deletedSecret: { _ in
|
SecretListView(store: store, activeSecret: $activeSecret, deletingSecret: $deletingSecret, deletedSecret: { _ in
|
||||||
activeSecret = nextDefaultSecret
|
activeSecret = nextDefaultSecret
|
||||||
@ -48,16 +40,11 @@ extension StoreListView {
|
|||||||
var nextDefaultSecret: AnyHashable? {
|
var nextDefaultSecret: AnyHashable? {
|
||||||
let fallback: AnyHashable
|
let fallback: AnyHashable
|
||||||
if storeList.modifiableStore?.isAvailable ?? false {
|
if storeList.modifiableStore?.isAvailable ?? false {
|
||||||
fallback = Constants.emptyStoreModifiableTag
|
fallback = EmptyStoreView.Constants.emptyStoreModifiableTag
|
||||||
} else {
|
} else {
|
||||||
fallback = Constants.emptyStoreTag
|
fallback = EmptyStoreView.Constants.emptyStoreTag
|
||||||
}
|
}
|
||||||
return storeList.stores.compactMap(\.secrets.first).first?.id ?? fallback
|
return storeList.stores.compactMap(\.secrets.first).first?.id ?? fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Constants {
|
|
||||||
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
|
||||||
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user