mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-22 13:37:07 +00:00
c80a6f1b0b
* Set up and start main content view * Continue * Setup flow * No secure storage view * Delete * Detail * Rename * More create * Empty. * List * Main app * Agent and bump * .
64 lines
2.0 KiB
Swift
64 lines
2.0 KiB
Swift
import SwiftUI
|
|
import SecretKit
|
|
|
|
struct SecretListItemView: View {
|
|
|
|
@ObservedObject var store: AnySecretStore
|
|
var secret: AnySecret
|
|
@Binding var activeSecret: AnySecret.ID?
|
|
|
|
@State var isDeleting: Bool = false
|
|
@State var isRenaming: Bool = false
|
|
|
|
var deletedSecret: (AnySecret) -> Void
|
|
var renamedSecret: (AnySecret) -> Void
|
|
|
|
var body: some View {
|
|
let showingPopupWrapped = Binding(
|
|
get: { isDeleting || isRenaming },
|
|
set: { if $0 == false { isDeleting = false; isRenaming = false } }
|
|
)
|
|
|
|
return NavigationLink(destination: SecretDetailView(secret: secret), tag: secret.id, selection: $activeSecret) {
|
|
if secret.requiresAuthentication {
|
|
HStack {
|
|
Text(secret.name)
|
|
Spacer()
|
|
Image(systemName: "lock")
|
|
}
|
|
} else {
|
|
Text(secret.name)
|
|
}
|
|
}
|
|
.contextMenu {
|
|
if store is AnySecretStoreModifiable {
|
|
Button(action: { isRenaming = true }) {
|
|
Text("secret_list_rename_button")
|
|
}
|
|
Button(action: { isDeleting = true }) {
|
|
Text("secret_list_delete_button")
|
|
}
|
|
}
|
|
}
|
|
.popover(isPresented: showingPopupWrapped) {
|
|
if let modifiable = store as? AnySecretStoreModifiable {
|
|
if isDeleting {
|
|
DeleteSecretView(store: modifiable, secret: secret) { deleted in
|
|
isDeleting = false
|
|
if deleted {
|
|
deletedSecret(secret)
|
|
}
|
|
}
|
|
} else if isRenaming {
|
|
RenameSecretView(store: modifiable, secret: secret) { renamed in
|
|
isRenaming = false
|
|
if renamed {
|
|
renamedSecret(secret)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|