mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-07 02:07:22 +01:00
Breaking up contentView more
This commit is contained in:
@@ -8,66 +8,19 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
|
||||
@EnvironmentObject var updater: UpdaterType
|
||||
@EnvironmentObject var agentStatusChecker: AgentStatusCheckerType
|
||||
|
||||
@State private var active: AnySecret.ID?
|
||||
@State private var showingCreation = false
|
||||
@State private var deletingSecret: AnySecret?
|
||||
@State private var selectedUpdate: Release?
|
||||
@Binding var runningSetup: Bool
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if storeList.anyAvailable {
|
||||
NavigationView {
|
||||
List(selection: $active) {
|
||||
ForEach(storeList.stores) { store in
|
||||
if store.isAvailable {
|
||||
Section(header: Text(store.name)) {
|
||||
if store.secrets.isEmpty {
|
||||
if store is AnySecretStoreModifiable {
|
||||
NavigationLink(destination: EmptyStoreModifiableView(), tag: Constants.emptyStoreModifiableTag, selection: $active) {
|
||||
Text("No Secrets")
|
||||
}
|
||||
} else {
|
||||
NavigationLink(destination: EmptyStoreView(), tag: Constants.emptyStoreTag, selection: $active) {
|
||||
Text("No Secrets")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ForEach(store.secrets) { secret in
|
||||
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: $active) {
|
||||
Text(secret.name)
|
||||
}.contextMenu {
|
||||
if store is AnySecretStoreModifiable {
|
||||
Button(action: { delete(secret: secret) }) {
|
||||
Text("Delete")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $deletingSecret) { secret in
|
||||
if let store = storeList.modifiableStore {
|
||||
DeleteSecretView(secret: secret, store: store) { deleted in
|
||||
deletingSecret = nil
|
||||
if deleted {
|
||||
active = nextDefaultSecret
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.onAppear {
|
||||
active = nextDefaultSecret
|
||||
}
|
||||
.frame(minWidth: 100, idealWidth: 240)
|
||||
StoreListView()
|
||||
.sheet(isPresented: $showingCreation) {
|
||||
if let store = storeList.modifiableStore {
|
||||
CreateSecretView(store: store, showing: $showingCreation)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NoStoresView()
|
||||
}
|
||||
@@ -141,28 +94,9 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func delete<SecretType: Secret>(secret: SecretType) {
|
||||
deletingSecret = AnySecret(secret)
|
||||
}
|
||||
|
||||
var nextDefaultSecret: AnyHashable? {
|
||||
let fallback: AnyHashable
|
||||
if storeList.modifiableStore?.isAvailable ?? false {
|
||||
fallback = Constants.emptyStoreModifiableTag
|
||||
} else {
|
||||
fallback = Constants.emptyStoreTag
|
||||
}
|
||||
return storeList.stores.compactMap(\.secrets.first).first?.id ?? fallback
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private enum Constants {
|
||||
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
||||
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
||||
}
|
||||
|
||||
//
|
||||
//#if DEBUG
|
||||
//
|
||||
|
||||
40
Secretive/Views/SecretListView.swift
Normal file
40
Secretive/Views/SecretListView.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import SwiftUI
|
||||
import SecretKit
|
||||
|
||||
struct SecretListView: View {
|
||||
|
||||
@ObservedObject var store: AnySecretStore
|
||||
@Binding var activeSecret: AnySecret.ID?
|
||||
@Binding var deletingSecret: AnySecret?
|
||||
|
||||
var deletedSecret: (AnySecret) -> Void
|
||||
|
||||
var body: some View {
|
||||
ForEach(store.secrets) { secret in
|
||||
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: $activeSecret) {
|
||||
Text(secret.name)
|
||||
}.contextMenu {
|
||||
if store is AnySecretStoreModifiable {
|
||||
Button(action: { delete(secret: secret) }) {
|
||||
Text("Delete")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $deletingSecret) { secret in
|
||||
if let modifiable = store as? AnySecretStoreModifiable {
|
||||
DeleteSecretView(secret: secret, store: modifiable) { deleted in
|
||||
deletingSecret = nil
|
||||
if deleted {
|
||||
deletedSecret(AnySecret(secret))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func delete<SecretType: Secret>(secret: SecretType) {
|
||||
deletingSecret = AnySecret(secret)
|
||||
}
|
||||
|
||||
}
|
||||
63
Secretive/Views/StoreListView.swift
Normal file
63
Secretive/Views/StoreListView.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
import SwiftUI
|
||||
import SecretKit
|
||||
|
||||
struct StoreListView: View {
|
||||
|
||||
@State private var activeSecret: AnySecret.ID?
|
||||
@State private var deletingSecret: AnySecret?
|
||||
|
||||
@EnvironmentObject var storeList: SecretStoreList
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List(selection: $activeSecret) {
|
||||
ForEach(storeList.stores) { store in
|
||||
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")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SecretListView(store: store, activeSecret: $activeSecret, deletingSecret: $deletingSecret, deletedSecret: { _ in
|
||||
activeSecret = nextDefaultSecret
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(SidebarListStyle())
|
||||
.onAppear {
|
||||
activeSecret = nextDefaultSecret
|
||||
}
|
||||
.frame(minWidth: 100, idealWidth: 240)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension StoreListView {
|
||||
|
||||
var nextDefaultSecret: AnyHashable? {
|
||||
let fallback: AnyHashable
|
||||
if storeList.modifiableStore?.isAvailable ?? false {
|
||||
fallback = Constants.emptyStoreModifiableTag
|
||||
} else {
|
||||
fallback = Constants.emptyStoreTag
|
||||
}
|
||||
return storeList.stores.compactMap(\.secrets.first).first?.id ?? fallback
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private enum Constants {
|
||||
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
||||
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
||||
}
|
||||
Reference in New Issue
Block a user