Add searchable instrument browser
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import MusicAssistantCore
|
||||
import SwiftUI
|
||||
|
||||
struct InstrumentBrowserView: View {
|
||||
private let catalog: LocalInstrumentCatalog
|
||||
|
||||
@State private var searchText = ""
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
init(catalog: LocalInstrumentCatalog = LocalInstrumentCatalog()) {
|
||||
self.catalog = catalog
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
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()
|
||||
}
|
||||
@@ -9,6 +9,7 @@ struct ProjectInspectorView: View {
|
||||
@State private var newInstrumentName = ""
|
||||
@State private var newVocalistLabel = ""
|
||||
@State private var newLanguageName = ""
|
||||
@State private var isInstrumentBrowserPresented = false
|
||||
@State private var isSaving = false
|
||||
@State private var saveStatus: SaveStatus?
|
||||
|
||||
@@ -62,6 +63,12 @@ struct ProjectInspectorView: View {
|
||||
}
|
||||
|
||||
Section("Instruments") {
|
||||
Button {
|
||||
isInstrumentBrowserPresented = true
|
||||
} label: {
|
||||
Label("Browse catalog", systemImage: "magnifyingglass")
|
||||
}
|
||||
|
||||
ForEach($project.instruments, id: \.instrumentId) { $instrument in
|
||||
Toggle(isOn: $instrument.selected) {
|
||||
Text(instrument.variant?.isEmpty == false ? instrument.variant ?? instrument.instrumentId : instrument.instrumentId)
|
||||
@@ -138,6 +145,9 @@ struct ProjectInspectorView: View {
|
||||
}
|
||||
}
|
||||
.background(Color(nsColor: .windowBackgroundColor))
|
||||
.sheet(isPresented: $isInstrumentBrowserPresented) {
|
||||
InstrumentBrowserView()
|
||||
}
|
||||
}
|
||||
|
||||
private var durationSecondsBinding: Binding<String> {
|
||||
|
||||
Reference in New Issue
Block a user