28 lines
659 B
Swift
28 lines
659 B
Swift
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 = []
|
||
|
|
}
|
||
|
|
}
|