Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs around selection after creating/deleting/updating keys #436

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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