Fix bugs around selection after creating/deleting/updating keys (#436)
* Fix bug where new secret wouldn't be selected * Remove keyboard shortcut for deletion
This commit is contained in:
parent
8679ca3da0
commit
480ef5392d
|
@ -8,7 +8,7 @@ public class SecretStoreList: ObservableObject {
|
|||
@Published public var stores: [AnySecretStore] = []
|
||||
/// A modifiable store, if one is available.
|
||||
@Published public var modifiableStore: AnySecretStoreModifiable?
|
||||
private var sinks: [AnyCancellable] = []
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
/// Initializes a SecretStoreList.
|
||||
public init() {
|
||||
|
@ -41,10 +41,9 @@ extension SecretStoreList {
|
|||
|
||||
private func addInternal(store: AnySecretStore) {
|
||||
stores.append(store)
|
||||
let sink = store.objectWillChange.sink {
|
||||
store.objectWillChange.sink {
|
||||
self.objectWillChange.send()
|
||||
}
|
||||
sinks.append(sink)
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
|
|||
@Binding var runningSetup: Bool
|
||||
@Binding var hasRunSetup: Bool
|
||||
@State var showingAgentInfo = false
|
||||
@State var activeSecret: AnySecret.ID?
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
@EnvironmentObject private var storeList: SecretStoreList
|
||||
|
@ -22,7 +23,7 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
|
|||
var body: some View {
|
||||
VStack {
|
||||
if storeList.anyAvailable {
|
||||
StoreListView(showingCreation: $showingCreation)
|
||||
StoreListView(activeSecret: $activeSecret)
|
||||
} else {
|
||||
NoStoresView()
|
||||
}
|
||||
|
@ -104,6 +105,10 @@ extension ContentView {
|
|||
.sheet(isPresented: $showingCreation) {
|
||||
if let modifiable = storeList.modifiableStore {
|
||||
CreateSecretView(store: modifiable, showing: $showingCreation)
|
||||
.onDisappear {
|
||||
guard let newest = modifiable.secrets.last?.id else { return }
|
||||
activeSecret = newest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
|||
Spacer()
|
||||
Button("Delete", action: delete)
|
||||
.disabled(confirm != secret.name)
|
||||
.keyboardShortcut(.delete)
|
||||
Button("Don't Delete") {
|
||||
dismissalBlock(false)
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@ struct SecretListItemView: View {
|
|||
} else {
|
||||
Text(secret.name)
|
||||
}
|
||||
}.contextMenu {
|
||||
}
|
||||
.contextMenu {
|
||||
if store is AnySecretStoreModifiable {
|
||||
Button(action: { isRenaming = true }) {
|
||||
Text("Rename")
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import SwiftUI
|
||||
import Combine
|
||||
import SecretKit
|
||||
|
||||
struct StoreListView: View {
|
||||
|
||||
@Binding var showingCreation: Bool
|
||||
|
||||
@State private var activeSecret: AnySecret.ID?
|
||||
@Binding var activeSecret: AnySecret.ID?
|
||||
|
||||
@EnvironmentObject private var storeList: SecretStoreList
|
||||
|
||||
|
@ -14,7 +13,7 @@ struct StoreListView: View {
|
|||
}
|
||||
|
||||
private func secretRenamed(secret: AnySecret) {
|
||||
activeSecret = nextDefaultSecret
|
||||
activeSecret = secret.id
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
|
Loading…
Reference in New Issue