2026-09-20 15:05:19 +02:00
|
|
|
// KeeVault/Views/EntryListView.swift
|
2026-09-19 17:11:02 +02:00
|
|
|
import SwiftUI
|
2026-09-20 15:05:19 +02:00
|
|
|
import KeeVaultCore
|
2026-09-19 17:11:02 +02:00
|
|
|
|
|
|
|
|
struct EntryListView: View {
|
|
|
|
|
@ObservedObject var vm: VaultViewModel
|
|
|
|
|
@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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-20 15:05:19 +02:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
|
.background(Color("VaultBackground"))
|
|
|
|
|
.navigationTitle("KeeVault")
|
2026-09-19 19:08:36 +02:00
|
|
|
.searchable(text: $vm.searchQuery, prompt: "Search entries…")
|
2026-09-19 17:11:02 +02:00
|
|
|
.toolbar {
|
|
|
|
|
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 ?? "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-19 17:25:06 +02:00
|
|
|
/// The most recently toggled-on filter group, if any filter is still active via it,
|
|
|
|
|
/// otherwise the vault root.
|
2026-09-19 17:11:02 +02:00
|
|
|
private var defaultGroupId: UUID {
|
2026-09-19 17:25:06 +02:00
|
|
|
vm.lastToggledGroupId ?? vm.session.database?.root.id ?? UUID()
|
2026-09-19 17:11:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|