48 lines
1.4 KiB
Swift
48 lines
1.4 KiB
Swift
//
|
|||
|
|
// SearchView.swift
|
||
|
|
// MyPass
|
||
|
|
//
|
||
|
|
// Search is embedded directly in GroupBrowserView via .searchable. SearchView is a
|
||
|
|
// standalone view for displaying search results when the query is active -- used in
|
||
|
|
// the macOS 3-column layout as the middle column when searching.
|
||
|
|
//
|
||
|
|
|
||
|
|
import SwiftUI
|
||
|
|
import MyPassCore
|
||
|
|
|
||
|
|
struct SearchView: View {
|
||
|
|
@ObservedObject var vm: VaultViewModel
|
||
|
|
@Binding var selectedEntry: Entry?
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
SwiftUI.Group {
|
||
|
|
if vm.filteredEntries.isEmpty {
|
||
|
|
ContentUnavailableView.search(text: vm.searchQuery)
|
||
|
|
} else {
|
||
|
|
List(vm.filteredEntries, selection: $selectedEntry) { entry in
|
||
|
|
#if os(macOS)
|
||
|
|
EntryListRow(entry: entry).tag(entry)
|
||
|
|
#else
|
||
|
|
NavigationLink(destination: EntryDetailView(entry: entry, session: vm.session)) {
|
||
|
|
EntryListRow(entry: entry)
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
struct EntryListRow: View {
|
||
|
|
let entry: Entry
|
||
|
|
var body: some View {
|
||
|
|
VStack(alignment: .leading, spacing: 2) {
|
||
|
|
Text(entry.title).font(.body)
|
||
|
|
Text(entry.username).font(.caption).foregroundStyle(.secondary)
|
||
|
|
if !entry.url.isEmpty {
|
||
|
|
Text(entry.url).font(.caption2).foregroundStyle(.tertiary)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|