75 lines
1.8 KiB
Swift
75 lines
1.8 KiB
Swift
//
|
|
// SidebarView.swift
|
|
// AutoCat2SUI
|
|
//
|
|
// Created by Selim Mustafaev on 12.02.2023.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AutoCatCore
|
|
import RealmSwift
|
|
|
|
struct SidebarSection: Identifiable {
|
|
|
|
let name: String
|
|
let filters: [Filter]
|
|
let id = UUID()
|
|
|
|
func contains(filter id: UUID) -> Bool {
|
|
filters.contains { $0.id == id }
|
|
}
|
|
}
|
|
|
|
struct SidebarView: View {
|
|
|
|
@ObservedResults(Vehicle.self) var vehicles
|
|
|
|
@Binding var selectedFilter: Filter?
|
|
@State private var checkSheetPresented = false
|
|
|
|
private let sections: [SidebarSection] = [
|
|
SidebarSection(name: "History", filters: [
|
|
.allLocal,
|
|
.unrecognized,
|
|
.outdated
|
|
]),
|
|
SidebarSection(name: "Remote", filters: [
|
|
.allRemote
|
|
])
|
|
]
|
|
|
|
var body: some View {
|
|
List(selection: $selectedFilter) {
|
|
ForEach(sections) { section in
|
|
Section(section.name) {
|
|
ForEach(section.filters, id: \.self) { filter in
|
|
Label(filter.name, systemImage: filter.iconName)
|
|
.badge(vehicles.filter(filter.match).count)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.navigationSplitViewColumnWidth(180)
|
|
.toolbar {
|
|
ToolbarItemGroup(placement: .primaryAction) {
|
|
Spacer()
|
|
Button {
|
|
checkSheetPresented = true
|
|
} label: {
|
|
Image(systemName: "plus")
|
|
}
|
|
.sheet(isPresented: $checkSheetPresented) {
|
|
CheckNumber()
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SidebarView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SidebarView(selectedFilter: .constant(nil))
|
|
}
|
|
}
|