mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-24 22:47:06 +00:00
Fixes #44
This commit is contained in:
parent
4a6e8c0b11
commit
84521cf8d6
@ -47,13 +47,7 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.onAppear {
|
}.onAppear {
|
||||||
let fallback: AnyHashable
|
self.active = self.nextDefaultSecret
|
||||||
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
|
|
||||||
}
|
}
|
||||||
.listStyle(SidebarListStyle())
|
.listStyle(SidebarListStyle())
|
||||||
.frame(minWidth: 100, idealWidth: 240)
|
.frame(minWidth: 100, idealWidth: 240)
|
||||||
@ -61,8 +55,11 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
|||||||
.navigationViewStyle(DoubleColumnNavigationViewStyle())
|
.navigationViewStyle(DoubleColumnNavigationViewStyle())
|
||||||
.sheet(isPresented: $showingDeletion) {
|
.sheet(isPresented: $showingDeletion) {
|
||||||
if self.storeList.modifiableStore != nil {
|
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
|
self.showingDeletion = false
|
||||||
|
if deleted {
|
||||||
|
self.active = self.nextDefaultSecret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,6 +86,16 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
|||||||
deletingSecret = AnySecret(secret)
|
deletingSecret = AnySecret(secret)
|
||||||
self.showingDeletion = true
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
|||||||
|
|
||||||
@State var confirm = ""
|
@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.secret = secret
|
||||||
self.store = store
|
self.store = store
|
||||||
self.dismissalBlock = dismissalBlock
|
self.dismissalBlock = dismissalBlock
|
||||||
@ -37,14 +37,16 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
|||||||
TextField(secret.name, text: $confirm)
|
TextField(secret.name, text: $confirm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onExitCommand(perform: dismissalBlock)
|
.onExitCommand {
|
||||||
|
self.dismissalBlock(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Button(action: delete) {
|
Button(action: delete) {
|
||||||
Text("Delete")
|
Text("Delete")
|
||||||
}.disabled(confirm != secret.name)
|
}.disabled(confirm != secret.name)
|
||||||
Button(action: dismissalBlock) {
|
Button(action: { self.dismissalBlock(false) }) {
|
||||||
Text("Don't Delete")
|
Text("Don't Delete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,6 +55,6 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
|||||||
|
|
||||||
func delete() {
|
func delete() {
|
||||||
try! store.delete(secret: secret)
|
try! store.delete(secret: secret)
|
||||||
dismissalBlock()
|
self.dismissalBlock(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user