- GroupFilterViewModel now tracks lastToggledGroupId (the single group most recently toggled to a non-empty selection), since toggling a group with subgroups expands selectedGroupIds to include the whole subtree, breaking the previous count==1 check used to infer the active filter group. - VaultViewModel exposes lastToggledGroupId, forwarded from GroupFilterViewModel by VaultRootView (ContentView.swift), and EntryListView.defaultGroupId now reads it instead of the broken selectedGroupIds.count == 1 check, so the add-entry sheet defaults new entries into the group actually being filtered by, not silently back to root. - EntryListView's search toggle button now clears vm.searchQuery when hiding the search bar, so a hidden bar can no longer keep filtering the list invisibly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
94 lines
3.2 KiB
Swift
94 lines
3.2 KiB
Swift
// MyPass/Views/EntryListView.swift
|
|
import SwiftUI
|
|
import MyPassCore
|
|
|
|
struct EntryListView: View {
|
|
@ObservedObject var vm: VaultViewModel
|
|
@State private var isSearching = false
|
|
@State private var showAddEntry = false
|
|
|
|
var body: some View {
|
|
List {
|
|
ForEach(vm.displayedEntries) { flatEntry in
|
|
NavigationLink(
|
|
destination: EntryDetailView(
|
|
entry: flatEntry.entry,
|
|
groupId: flatEntry.parentGroupId,
|
|
session: vm.session
|
|
)
|
|
) {
|
|
EntryRow(flatEntry: flatEntry)
|
|
}
|
|
}
|
|
.onDelete { offsets in
|
|
offsets.map { vm.displayedEntries[$0] }.forEach(vm.deleteEntry)
|
|
}
|
|
}
|
|
.navigationTitle("MyPass")
|
|
.searchable(text: $vm.searchQuery, isPresented: $isSearching, prompt: "Search entries…")
|
|
.toolbar {
|
|
ToolbarItem(placement: .primaryAction) {
|
|
Button {
|
|
if isSearching { vm.searchQuery = "" }
|
|
isSearching.toggle()
|
|
} label: {
|
|
Image(systemName: "magnifyingglass")
|
|
}
|
|
}
|
|
ToolbarItem(placement: .primaryAction) {
|
|
Button { showAddEntry = true } label: {
|
|
Image(systemName: "plus")
|
|
}
|
|
}
|
|
}
|
|
.sheet(isPresented: $showAddEntry) {
|
|
EntryEditView(vm: EntryEditViewModel(session: vm.session, groupId: defaultGroupId))
|
|
}
|
|
.alert("Error", isPresented: Binding(
|
|
get: { vm.errorMessage != nil },
|
|
set: { if !$0 { vm.errorMessage = nil } }
|
|
)) {
|
|
Button("OK", role: .cancel) { vm.errorMessage = nil }
|
|
} message: {
|
|
Text(vm.errorMessage ?? "")
|
|
}
|
|
}
|
|
|
|
/// The most recently toggled-on filter group, if any filter is still active via it,
|
|
/// otherwise the vault root.
|
|
private var defaultGroupId: UUID {
|
|
vm.lastToggledGroupId ?? vm.session.database?.root.id ?? UUID()
|
|
}
|
|
}
|
|
|
|
private struct EntryRow: View {
|
|
let flatEntry: FlatEntry
|
|
|
|
private var breadcrumbText: String? {
|
|
guard !flatEntry.breadcrumb.isEmpty else { return nil }
|
|
return flatEntry.breadcrumb.map(\.name).joined(separator: " > ")
|
|
}
|
|
|
|
var body: some View {
|
|
HStack(alignment: .top, spacing: 12) {
|
|
Image(systemName: KeePassIconMapper.symbolName(forIconIndex: flatEntry.entry.iconIndex))
|
|
.foregroundStyle(.secondary)
|
|
.frame(width: 24)
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(flatEntry.entry.title).font(.body)
|
|
if let breadcrumbText {
|
|
Text("\(flatEntry.entry.username) · \(breadcrumbText)")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
.truncationMode(.middle)
|
|
} else {
|
|
Text(flatEntry.entry.username)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|