mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-08-26 23:20:57 +00:00
* Slim package * Cleanup * . * Expose tokenID. * Expose some constants. * Open. * Combine cleanup * Make eraser base public. * Reload * Fix concurrency issue on key insertion. * Add capabilities. * . * Revert "." This reverts commit7c5c2924fa
. * Revert "Add capabilities." This reverts commitbfa7a3cd51
.
63 lines
1.9 KiB
Swift
63 lines
1.9 KiB
Swift
import SwiftUI
|
|
import SecretKit
|
|
|
|
struct StoreListView: View {
|
|
|
|
@Binding var activeSecret: AnySecret?
|
|
|
|
@Environment(\.secretStoreList) private var storeList
|
|
|
|
private func secretDeleted(secret: AnySecret) {
|
|
activeSecret = nextDefaultSecret
|
|
}
|
|
|
|
private func secretRenamed(secret: AnySecret) {
|
|
activeSecret = secret
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationSplitView {
|
|
List(selection: $activeSecret) {
|
|
ForEach(storeList.stores) { store in
|
|
if store.isAvailable {
|
|
Section(header: Text(store.name)) {
|
|
ForEach(store.secrets) { secret in
|
|
SecretListItemView(
|
|
store: store,
|
|
secret: secret,
|
|
deletedSecret: secretDeleted,
|
|
renamedSecret: secretRenamed
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} detail: {
|
|
if let activeSecret {
|
|
SecretDetailView(secret: activeSecret)
|
|
} else if let nextDefaultSecret {
|
|
// This just means onAppear hasn't executed yet.
|
|
// Do this to avoid a blip.
|
|
SecretDetailView(secret: nextDefaultSecret)
|
|
} else {
|
|
EmptyStoreView(store: storeList.modifiableStore ?? storeList.stores.first)
|
|
}
|
|
}
|
|
.navigationSplitViewStyle(.balanced)
|
|
.onAppear {
|
|
activeSecret = nextDefaultSecret
|
|
}
|
|
.frame(minWidth: 100, idealWidth: 240)
|
|
|
|
}
|
|
}
|
|
|
|
extension StoreListView {
|
|
|
|
private var nextDefaultSecret: AnySecret? {
|
|
return storeList.stores.first(where: { !$0.secrets.isEmpty })?.secrets.first
|
|
}
|
|
|
|
}
|