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] = [] @Published public var stores: [AnySecretStore] = []
/// A modifiable store, if one is available. /// A modifiable store, if one is available.
@Published public var modifiableStore: AnySecretStoreModifiable? @Published public var modifiableStore: AnySecretStoreModifiable?
private var sinks: [AnyCancellable] = [] private var cancellables: Set<AnyCancellable> = []
/// Initializes a SecretStoreList. /// Initializes a SecretStoreList.
public init() { public init() {
@ -41,10 +41,9 @@ extension SecretStoreList {
private func addInternal(store: AnySecretStore) { private func addInternal(store: AnySecretStore) {
stores.append(store) stores.append(store)
let sink = store.objectWillChange.sink { store.objectWillChange.sink {
self.objectWillChange.send() self.objectWillChange.send()
} }.store(in: &cancellables)
sinks.append(sink)
} }
} }

View File

@ -10,6 +10,7 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
@Binding var runningSetup: Bool @Binding var runningSetup: Bool
@Binding var hasRunSetup: Bool @Binding var hasRunSetup: Bool
@State var showingAgentInfo = false @State var showingAgentInfo = false
@State var activeSecret: AnySecret.ID?
@Environment(\.colorScheme) var colorScheme @Environment(\.colorScheme) var colorScheme
@EnvironmentObject private var storeList: SecretStoreList @EnvironmentObject private var storeList: SecretStoreList
@ -22,7 +23,7 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
var body: some View { var body: some View {
VStack { VStack {
if storeList.anyAvailable { if storeList.anyAvailable {
StoreListView(showingCreation: $showingCreation) StoreListView(activeSecret: $activeSecret)
} else { } else {
NoStoresView() NoStoresView()
} }
@ -104,6 +105,10 @@ extension ContentView {
.sheet(isPresented: $showingCreation) { .sheet(isPresented: $showingCreation) {
if let modifiable = storeList.modifiableStore { if let modifiable = storeList.modifiableStore {
CreateSecretView(store: modifiable, showing: $showingCreation) 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() Spacer()
Button("Delete", action: delete) Button("Delete", action: delete)
.disabled(confirm != secret.name) .disabled(confirm != secret.name)
.keyboardShortcut(.delete)
Button("Don't Delete") { Button("Don't Delete") {
dismissalBlock(false) dismissalBlock(false)
} }

View File

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

View File

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