This commit is contained in:
Max Goedjen 2020-03-15 14:03:57 -07:00
parent 4a6e8c0b11
commit 84521cf8d6
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
2 changed files with 22 additions and 13 deletions

View File

@ -47,13 +47,7 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
}
}
}.onAppear {
let fallback: AnyHashable
if self.storeList.modifiableStore?.isAvailable ?? false {
fallback = Constants.emptyStoreModifiableTag
} else {
fallback = Constants.emptyStoreTag
}
self.active = self.storeList.stores.compactMap { $0.secrets.first }.first?.id ?? fallback
self.active = self.nextDefaultSecret
}
.listStyle(SidebarListStyle())
.frame(minWidth: 100, idealWidth: 240)
@ -61,8 +55,11 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.sheet(isPresented: $showingDeletion) {
if self.storeList.modifiableStore != nil {
DeleteSecretView(secret: self.deletingSecret!, store: self.storeList.modifiableStore!) {
DeleteSecretView(secret: self.deletingSecret!, store: self.storeList.modifiableStore!) { deleted in
self.showingDeletion = false
if deleted {
self.active = self.nextDefaultSecret
}
}
}
}
@ -89,6 +86,16 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
deletingSecret = AnySecret(secret)
self.showingDeletion = true
}
var nextDefaultSecret: AnyHashable? {
let fallback: AnyHashable
if self.storeList.modifiableStore?.isAvailable ?? false {
fallback = Constants.emptyStoreModifiableTag
} else {
fallback = Constants.emptyStoreTag
}
return self.storeList.stores.compactMap { $0.secrets.first }.first?.id ?? fallback
}
}

View File

@ -8,9 +8,9 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
@State var confirm = ""
fileprivate var dismissalBlock: () -> ()
fileprivate var dismissalBlock: (Bool) -> ()
init(secret: StoreType.SecretType, store: StoreType, dismissalBlock: @escaping () -> ()) {
init(secret: StoreType.SecretType, store: StoreType, dismissalBlock: @escaping (Bool) -> ()) {
self.secret = secret
self.store = store
self.dismissalBlock = dismissalBlock
@ -37,14 +37,16 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
TextField(secret.name, text: $confirm)
}
}
.onExitCommand(perform: dismissalBlock)
.onExitCommand {
self.dismissalBlock(false)
}
}
HStack {
Spacer()
Button(action: delete) {
Text("Delete")
}.disabled(confirm != secret.name)
Button(action: dismissalBlock) {
Button(action: { self.dismissalBlock(false) }) {
Text("Don't Delete")
}
}
@ -53,6 +55,6 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
func delete() {
try! store.delete(secret: secret)
dismissalBlock()
self.dismissalBlock(true)
}
}