new song structure

This commit is contained in:
2025-10-21 11:38:48 +02:00
parent 59328aaaed
commit 3a5d449424
11 changed files with 807 additions and 175 deletions
+60 -4
View File
@@ -12,6 +12,7 @@ import { navigate } from "../../navigation/NavigationService";
import { useUser } from "../../providers/UserDataProvider";
import { Palette, Style } from "../../styles";
import { FONT_FAMILY } from "../../styles/Fonts";
import { sanitizeStructureList } from "../../utils/songStructure";
const CreatingLyrics = ({ active, config, selections }) => {
const [progress, setProgress] = useState(0);
@@ -58,6 +59,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
console.log("🚀 [CreatingLyrics] Lancement de la génération", {
platform: Platform.OS,
});
const sanitizedStructure = sanitizeStructureList(config?.structure);
const callable = firebase
.functions()
.httpsCallable("lyrics-generateLyrics");
@@ -67,10 +69,32 @@ const CreatingLyrics = ({ active, config, selections }) => {
emotion: config?.emotion,
style: config?.style,
audience: config?.audience,
structure: config?.structure,
structure: sanitizedStructure,
rhymes: config?.rhymes,
});
setResult(data);
const rawLyrics = Array.isArray(data?.lyrics) ? data.lyrics : [];
const normalizedLyrics = rawLyrics.map((section) => {
const sanitizedType =
sanitizeStructureList([section?.type])[0] || section?.type || "";
return {
...section,
type: sanitizedType,
};
});
const alignedLyrics =
sanitizedStructure.length > 0 &&
sanitizedStructure.length === normalizedLyrics.length
? normalizedLyrics.map((section, index) => ({
...section,
type: sanitizedStructure[index],
}))
: normalizedLyrics;
const processedResult = {
...data,
lyrics: alignedLyrics,
structure: sanitizedStructure,
};
setResult(processedResult);
setProgress(100);
console.log("✨ [CreatingLyrics] Génération réussie");
} catch (e) {
@@ -106,12 +130,44 @@ const CreatingLyrics = ({ active, config, selections }) => {
setSaved(true);
await setIsLoading(true);
console.log("💾 [CreatingLyrics] Sauvegarde automatique des paroles");
const sanitizedStructure = sanitizeStructureList(
result?.structure || config?.structure
);
const baseConfig =
config && typeof config === "object" && !Array.isArray(config)
? { ...config }
: {};
if (sanitizedStructure.length > 0) {
baseConfig.structure = sanitizedStructure;
} else if (Object.prototype.hasOwnProperty.call(baseConfig, "structure")) {
delete baseConfig.structure;
}
const persistedConfig =
Object.keys(baseConfig).length > 0 ? baseConfig : null;
let persistedSelections =
selections && typeof selections === "object" && !Array.isArray(selections)
? { ...selections }
: null;
if (persistedSelections) {
if ("customStructure" in persistedSelections) {
persistedSelections.customStructure = sanitizeStructureList(
persistedSelections.customStructure
);
}
if ("parsedStructure" in persistedSelections) {
persistedSelections.parsedStructure = sanitizeStructureList(
persistedSelections.parsedStructure
);
}
}
await updateProjectData({
title: result?.title || "",
lyrics: Array.isArray(result?.lyrics) ? result.lyrics : [],
description: result?.lyricsDescription,
config: config || null,
selections: selections || null,
config: persistedConfig,
selections: persistedSelections,
hasLyrics: false,
});
navigate(Routes.Lyrics);