secretive/Secretive/ContentView.swift

46 lines
1.4 KiB
Swift
Raw Normal View History

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