88 lines
2.9 KiB
Swift
88 lines
2.9 KiB
Swift
import MusicAssistantCore
|
|
import SwiftUI
|
|
|
|
struct InstrumentBrowserView: View {
|
|
private let catalog: LocalInstrumentCatalog
|
|
|
|
@State private var searchText = ""
|
|
@State private var selectedFamilyCategory: String?
|
|
@State private var selectedRegionOrigin: String?
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
init(catalog: LocalInstrumentCatalog = LocalInstrumentCatalog()) {
|
|
self.catalog = catalog
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
VStack(spacing: 0) {
|
|
HStack {
|
|
Picker("Family", selection: $selectedFamilyCategory) {
|
|
Text("All families").tag(String?.none)
|
|
|
|
ForEach(catalog.familyCategories, id: \.self) { familyCategory in
|
|
Text(familyCategory).tag(Optional(familyCategory))
|
|
}
|
|
}
|
|
.pickerStyle(.menu)
|
|
|
|
Spacer()
|
|
|
|
Picker("Region", selection: $selectedRegionOrigin) {
|
|
Text("All regions").tag(String?.none)
|
|
|
|
ForEach(catalog.regionsOfOrigin, id: \.self) { regionOrigin in
|
|
Text(regionOrigin).tag(Optional(regionOrigin))
|
|
}
|
|
}
|
|
.pickerStyle(.menu)
|
|
}
|
|
.padding(.horizontal)
|
|
.padding(.vertical, 8)
|
|
|
|
Divider()
|
|
|
|
List(
|
|
catalog.instruments(
|
|
matching: searchText,
|
|
familyCategory: selectedFamilyCategory,
|
|
regionOrigin: selectedRegionOrigin
|
|
),
|
|
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")
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Done") {
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.frame(minWidth: 460, minHeight: 520)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
InstrumentBrowserView()
|
|
}
|