Skip to content

Commit

Permalink
Fix bugs around selection after creating/deleting/updating keys (#436)
Browse files Browse the repository at this point in the history
* Fix bug where new secret wouldn't be selected

* Remove keyboard shortcut for deletion
  • Loading branch information
maxgoedjen authored Dec 23, 2022
1 parent 8679ca3 commit 480ef53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
7 changes: 3 additions & 4 deletions Sources/Packages/Sources/SecretKit/SecretStoreList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}

}
7 changes: 6 additions & 1 deletion Sources/Secretive/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Secretive/Views/DeleteSecretView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Secretive/Views/SecretListItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct SecretListItemView: View {
} else {
Text(secret.name)
}
}.contextMenu {
}
.contextMenu {
if store is AnySecretStoreModifiable {
Button(action: { isRenaming = true }) {
Text("Rename")
Expand Down
7 changes: 3 additions & 4 deletions Sources/Secretive/Views/StoreListView.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
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) {
activeSecret = nextDefaultSecret
}

private func secretRenamed(secret: AnySecret) {
activeSecret = nextDefaultSecret
activeSecret = secret.id
}

var body: some View {
Expand Down

0 comments on commit 480ef53

Please sign in to comment.