Persist selections and compile song output
This commit is contained in:
@@ -156,9 +156,12 @@ struct FinalReviewView: View {
|
||||
|
||||
private func ensureSunoOutput() {
|
||||
guard project.sunoOutput == nil else { return }
|
||||
let compiledOutput = (try? SongProjectPromptCompiler().compile(project: project))
|
||||
?? CompiledSunoOutput(lyricsText: project.lyrics.text, stylePrompt: "")
|
||||
|
||||
project.sunoOutput = SunoOutput(
|
||||
lyricsText: project.lyrics.text,
|
||||
stylePrompt: "",
|
||||
lyricsText: compiledOutput.lyricsText,
|
||||
stylePrompt: compiledOutput.stylePrompt,
|
||||
generatedAt: Date()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,18 +3,23 @@ import SwiftUI
|
||||
|
||||
struct InstrumentBrowserView: View {
|
||||
@Binding private var project: SongProject
|
||||
private let saveProject: (SongProject) async -> Bool
|
||||
private let catalog: LocalInstrumentCatalog
|
||||
|
||||
@State private var searchText = ""
|
||||
@State private var selectedFamilyCategory: String?
|
||||
@State private var selectedRegionOrigin: String?
|
||||
@State private var hasUnsavedSelectionChanges = false
|
||||
@State private var isSaving = false
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
init(
|
||||
project: Binding<SongProject>,
|
||||
saveProject: @escaping (SongProject) async -> Bool = { _ in true },
|
||||
catalog: LocalInstrumentCatalog = LocalInstrumentCatalog()
|
||||
) {
|
||||
_project = project
|
||||
self.saveProject = saveProject
|
||||
self.catalog = catalog
|
||||
}
|
||||
|
||||
@@ -81,12 +86,33 @@ struct InstrumentBrowserView: View {
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
Task {
|
||||
await saveSelectionChangesIfNeeded()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
.disabled(isSaving)
|
||||
}
|
||||
|
||||
if isSaving {
|
||||
ToolbarItem(placement: .status) {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 460, minHeight: 520)
|
||||
.onDisappear {
|
||||
guard hasUnsavedSelectionChanges, !isSaving else { return }
|
||||
|
||||
let projectToSave = project
|
||||
hasUnsavedSelectionChanges = false
|
||||
|
||||
Task {
|
||||
_ = await saveProject(projectToSave)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func selectionBinding(for instrument: InstrumentCatalogItem) -> Binding<Bool> {
|
||||
@@ -98,8 +124,18 @@ struct InstrumentBrowserView: View {
|
||||
isSelected: isSelected,
|
||||
variant: instrument.name
|
||||
)
|
||||
hasUnsavedSelectionChanges = true
|
||||
}
|
||||
}
|
||||
|
||||
private func saveSelectionChangesIfNeeded() async {
|
||||
guard hasUnsavedSelectionChanges else { return }
|
||||
|
||||
isSaving = true
|
||||
let didSave = await saveProject(project)
|
||||
hasUnsavedSelectionChanges = !didSave
|
||||
isSaving = false
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
||||
@@ -146,7 +146,7 @@ struct ProjectInspectorView: View {
|
||||
}
|
||||
.background(Color(nsColor: .windowBackgroundColor))
|
||||
.sheet(isPresented: $isInstrumentBrowserPresented) {
|
||||
InstrumentBrowserView(project: $project)
|
||||
InstrumentBrowserView(project: $project, saveProject: saveProject)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user