Add instrument family filtering
This commit is contained in:
@@ -5,6 +5,7 @@ struct InstrumentBrowserView: View {
|
||||
private let catalog: LocalInstrumentCatalog
|
||||
|
||||
@State private var searchText = ""
|
||||
@State private var selectedFamilyCategory: String?
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
init(catalog: LocalInstrumentCatalog = LocalInstrumentCatalog()) {
|
||||
@@ -13,23 +14,44 @@ struct InstrumentBrowserView: View {
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List(catalog.instruments(matching: searchText), id: \.id) { instrument in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(instrument.name)
|
||||
.font(.body.weight(.medium))
|
||||
VStack(spacing: 0) {
|
||||
Picker("Family", selection: $selectedFamilyCategory) {
|
||||
Text("All families").tag(String?.none)
|
||||
|
||||
HStack(spacing: 6) {
|
||||
Text(instrument.familyCategory)
|
||||
|
||||
if let regionOrigin = instrument.regionOrigin {
|
||||
Text(regionOrigin)
|
||||
}
|
||||
ForEach(catalog.familyCategories, id: \.self) { familyCategory in
|
||||
Text(familyCategory).tag(Optional(familyCategory))
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
.pickerStyle(.menu)
|
||||
.padding(.horizontal)
|
||||
.padding(.vertical, 8)
|
||||
|
||||
Divider()
|
||||
|
||||
List(
|
||||
catalog.instruments(
|
||||
matching: searchText,
|
||||
familyCategory: selectedFamilyCategory
|
||||
),
|
||||
id: \.id
|
||||
) { instrument in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(instrument.name)
|
||||
.font(.body.weight(.medium))
|
||||
|
||||
HStack(spacing: 6) {
|
||||
Text(instrument.familyCategory)
|
||||
|
||||
if let regionOrigin = instrument.regionOrigin {
|
||||
Text(regionOrigin)
|
||||
}
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Instrument Catalog")
|
||||
.searchable(text: $searchText, prompt: "Search instruments")
|
||||
|
||||
Reference in New Issue
Block a user