Fill Suno fields with accessibility adapter
This commit is contained in:
@@ -4,11 +4,20 @@ import SwiftUI
|
||||
struct FinalReviewView: View {
|
||||
@Binding var project: SongProject
|
||||
@Environment(\.openURL) private var openURL
|
||||
private let sunoFieldFiller: any SunoFieldFilling
|
||||
|
||||
@State private var newFieldKey = ""
|
||||
@State private var newFieldValue = ""
|
||||
@State private var handoffStatus: HandoffStatus?
|
||||
|
||||
init(
|
||||
project: Binding<SongProject>,
|
||||
sunoFieldFiller: any SunoFieldFilling = MacOSSunoAccessibilityFieldFiller()
|
||||
) {
|
||||
_project = project
|
||||
self.sunoFieldFiller = sunoFieldFiller
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
ArabicLyricsReviewView(project: $project)
|
||||
@@ -196,21 +205,37 @@ struct FinalReviewView: View {
|
||||
}
|
||||
|
||||
openURL(SunoHandoffDestination.createPageURL) { accepted in
|
||||
handoffStatus = accepted
|
||||
? .opened
|
||||
: .failed("Unable to open the Suno Create page.")
|
||||
guard accepted else {
|
||||
handoffStatus = .failed("Unable to open the Suno Create page.")
|
||||
return
|
||||
}
|
||||
|
||||
let payload = SunoHandoffPayload(
|
||||
title: project.title,
|
||||
lyrics: output.lyricsText,
|
||||
stylePrompt: output.stylePrompt
|
||||
)
|
||||
Task {
|
||||
handoffStatus = .fieldFill(await sunoFieldFiller.fill(payload))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum HandoffStatus: Equatable {
|
||||
case opened
|
||||
case fieldFill(SunoFieldFillReport)
|
||||
case failed(String)
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .opened:
|
||||
return "Suno Create opened in your browser."
|
||||
case let .fieldFill(report):
|
||||
let fieldsToCopy = report.results.compactMap { field, result in
|
||||
if case .copyRequired = result { return field.displayName }
|
||||
return nil
|
||||
}
|
||||
return fieldsToCopy.isEmpty
|
||||
? "Suno fields filled in your browser."
|
||||
: "Copy these fields into Suno: \(fieldsToCopy.joined(separator: ", "))."
|
||||
case let .failed(message):
|
||||
return message
|
||||
}
|
||||
@@ -218,8 +243,10 @@ private enum HandoffStatus: Equatable {
|
||||
|
||||
var systemImage: String {
|
||||
switch self {
|
||||
case .opened:
|
||||
return "checkmark.circle.fill"
|
||||
case let .fieldFill(report):
|
||||
return report.results.values.contains { if case .copyRequired = $0 { return true }; return false }
|
||||
? "exclamationmark.triangle.fill"
|
||||
: "checkmark.circle.fill"
|
||||
case .failed:
|
||||
return "exclamationmark.triangle.fill"
|
||||
}
|
||||
@@ -227,8 +254,10 @@ private enum HandoffStatus: Equatable {
|
||||
|
||||
var foregroundStyle: Color {
|
||||
switch self {
|
||||
case .opened:
|
||||
return .green
|
||||
case let .fieldFill(report):
|
||||
return report.results.values.contains { if case .copyRequired = $0 { return true }; return false }
|
||||
? .orange
|
||||
: .green
|
||||
case .failed:
|
||||
return .red
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user