secretive/Secretive/ContentView.swift
2020-03-06 22:21:10 -08:00

46 lines
1.4 KiB
Swift

import SwiftUI
import SecretKit
struct ContentView<StoreType: SecretStore>: View {
@ObservedObject var store: StoreType
@State var active: StoreType.SecretType?
var body: some View {
NavigationView {
List {
Section(header: Text(store.name)) {
ForEach(store.secrets) { secret in
NavigationLink(destination: SecretDetailView(secret: secret), tag: secret, selection: self.$active) {
Text(secret.name)
}.contextMenu {
Button(action: { self.delete(secret: secret) }) {
Text("Delete")
}
}
}
}
}.onAppear {
self.active = self.store.secrets.first
}
.listStyle(SidebarListStyle())
.frame(minWidth: 100, idealWidth: 240)
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
func delete(secret: StoreType.SecretType) {
// TODO: Add "type the name of the key to delete" dialogue
try! store.delete(secret: secret)
}
}
//
//struct ContentView_Previews: PreviewProvider {
// static var previews: some View {
// ContentView(store: Preview.Store(numberOfRandomSecrets: 10))
// }
//}