feat: add SearchView
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user