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:
Max Goedjen 2022-12-22 23:29:51 -05:00 committed by GitHub
parent 8679ca3da0
commit 480ef5392d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 11 deletions

View File

@ -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)
}
}

View File

@ -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
}
}
}
}

View File

@ -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)
}

View File

@ -29,7 +29,8 @@ struct SecretListItemView: View {
} else {
Text(secret.name)
}
}.contextMenu {
}
.contextMenu {
if store is AnySecretStoreModifiable {
Button(action: { isRenaming = true }) {
Text("Rename")

View File

@ -1,12 +1,11 @@
import SwiftUI
import Combine
import SecretKit
struct StoreListView: View {
@Binding var showingCreation: Bool
@Binding var activeSecret: AnySecret.ID?
@State private var activeSecret: AnySecret.ID?
@EnvironmentObject private var storeList: SecretStoreList
private func secretDeleted(secret: AnySecret) {
@ -14,7 +13,7 @@ struct StoreListView: View {
}
private func secretRenamed(secret: AnySecret) {
activeSecret = nextDefaultSecret
activeSecret = secret.id
}
var body: some View {