feat: add GroupFilterViewModel and GroupFilterView sidebar
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
import Foundation
|
||||||
|
import Combine
|
||||||
|
import MyPassCore
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
final class GroupFilterViewModel: ObservableObject {
|
||||||
|
@Published var selectedGroupIds: Set<UUID> = []
|
||||||
|
|
||||||
|
private let session: VaultSession
|
||||||
|
|
||||||
|
init(session: VaultSession) {
|
||||||
|
self.session = session
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSelected(_ group: MyPassCore.Group) -> Bool {
|
||||||
|
selectedGroupIds.contains(group.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func toggle(_ group: MyPassCore.Group) {
|
||||||
|
guard let root = session.database?.root else { return }
|
||||||
|
selectedGroupIds = GroupSelection.toggling(group.id, in: root, current: selectedGroupIds)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clear() {
|
||||||
|
selectedGroupIds = []
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import MyPassCore
|
||||||
|
|
||||||
|
struct GroupFilterView: View {
|
||||||
|
@ObservedObject var vm: GroupFilterViewModel
|
||||||
|
let rootGroup: MyPassCore.Group
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
List {
|
||||||
|
if !vm.selectedGroupIds.isEmpty {
|
||||||
|
Button("Clear Filter", action: vm.clear)
|
||||||
|
}
|
||||||
|
GroupFilterNode(group: rootGroup, vm: vm)
|
||||||
|
}
|
||||||
|
.navigationTitle("Groups")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct GroupFilterNode: View {
|
||||||
|
let group: MyPassCore.Group
|
||||||
|
@ObservedObject var vm: GroupFilterViewModel
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if group.subgroups.isEmpty {
|
||||||
|
row
|
||||||
|
} else {
|
||||||
|
DisclosureGroup {
|
||||||
|
ForEach(group.subgroups) { sub in
|
||||||
|
GroupFilterNode(group: sub, vm: vm)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
row
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var row: some View {
|
||||||
|
Button {
|
||||||
|
vm.toggle(group)
|
||||||
|
} label: {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: vm.isSelected(group) ? "checkmark.circle.fill" : "circle")
|
||||||
|
.foregroundStyle(vm.isSelected(group) ? Color.accentColor : Color.secondary)
|
||||||
|
Label(group.name, systemImage: "folder")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user