fix web flow

This commit is contained in:
2025-10-02 14:24:19 +02:00
parent 0ccdcf3084
commit 6f25cad83f
6 changed files with 194 additions and 91 deletions
+63 -32
View File
@@ -5,6 +5,7 @@ import { SwiperFlatList } from "react-native-swiper-flatlist";
import { background } from "../../assets";
import GradientButton from "../../components/GradientButton";
import MusicLandHeader from "../../components/MusicLandHeader";
import { OTHER_OBJECTIVE_OPTION, OTHER_STYLE_OPTION } from "../../data/data";
import useLayoutType from "../../hooks/useLayoutType";
import Page from "../../layouts/Page";
import { Routes } from "../../navigation";
@@ -44,6 +45,18 @@ const CreateLyricsWithAi = () => {
const [rhymes, setRhymes] = useState(null);
const [customStructure, setCustomStructure] = useState(null); // array like ['couplet','refrain']
const trimmedOtherObjective =
typeof otherObjective === "string" ? otherObjective.trim() : "";
const shouldUseOtherObjective = objective === OTHER_OBJECTIVE_OPTION;
const persistedOtherObjective = shouldUseOtherObjective
? trimmedOtherObjective
: "";
const trimmedOtherStyle =
typeof otherStyle === "string" ? otherStyle.trim() : "";
const shouldUseOtherStyle = style === OTHER_STYLE_OPTION;
const persistedOtherStyle = shouldUseOtherStyle ? trimmedOtherStyle : "";
// Pré-remplir les états depuis le projet sélectionné si disponibles
React.useEffect(() => {
if (!selectedProject) return;
@@ -52,19 +65,28 @@ const CreateLyricsWithAi = () => {
const rawOtherObjective =
typeof sel.otherObjective === "string" ? sel.otherObjective : "";
const hasSavedOtherObjective = rawOtherObjective.trim().length > 0;
const trimmedSavedOtherObjective = rawOtherObjective.trim();
const hasSavedOtherObjective = trimmedSavedOtherObjective.length > 0;
const savedObjective =
typeof sel.objective === "string" && sel.objective.trim().length > 0
? sel.objective
? sel.objective.trim()
: null;
if (!otherObjective && hasSavedOtherObjective) {
setOtherObjective(rawOtherObjective);
if (objective !== null) {
setObjective(null);
}
} else if (!hasSavedOtherObjective && objective == null && savedObjective) {
setObjective(savedObjective);
}
const shouldSelectOtherObjective =
hasSavedOtherObjective &&
(!savedObjective || savedObjective === OTHER_OBJECTIVE_OPTION);
const resolvedSavedObjective = shouldSelectOtherObjective
? OTHER_OBJECTIVE_OPTION
: savedObjective;
if (resolvedSavedObjective && objective !== resolvedSavedObjective) {
setObjective(resolvedSavedObjective);
} else if (!resolvedSavedObjective && objective !== null) {
setObjective(null);
}
if (!context && typeof sel.context === "string") setContext(sel.context);
@@ -86,19 +108,24 @@ const CreateLyricsWithAi = () => {
const rawOtherStyle =
typeof sel.otherStyle === "string" ? sel.otherStyle : "";
const hasSavedOtherStyle = rawOtherStyle.trim().length > 0;
const trimmedSavedOtherStyle = rawOtherStyle.trim();
const hasSavedOtherStyle = trimmedSavedOtherStyle.length > 0;
const savedStyle =
typeof sel.style === "string" && sel.style.trim().length > 0
? sel.style
? sel.style.trim()
: null;
if (!otherStyle && hasSavedOtherStyle) {
setOtherStyle(rawOtherStyle);
if (style !== null) {
setStyle(null);
}
} else if (!hasSavedOtherStyle && style == null && savedStyle) {
setStyle(savedStyle);
}
const shouldSelectOtherStyle =
hasSavedOtherStyle && (!savedStyle || savedStyle === OTHER_STYLE_OPTION);
const resolvedSavedStyle = shouldSelectOtherStyle
? OTHER_STYLE_OPTION
: savedStyle;
if (resolvedSavedStyle && style !== resolvedSavedStyle) {
setStyle(resolvedSavedStyle);
} else if (!resolvedSavedStyle && style !== null) {
setStyle(null);
}
if (!audience && typeof sel.audience === "string")
setAudience(sel.audience);
@@ -154,16 +181,21 @@ const CreateLyricsWithAi = () => {
}, [hasLyrics]);
const lyricsConfig = useMemo(() => {
const resolvedObjective = shouldUseOtherObjective
? persistedOtherObjective || undefined
: objective || undefined;
const resolvedStyle = shouldUseOtherStyle
? persistedOtherStyle || undefined
: style || undefined;
return {
objective: otherObjective?.trim()
? otherObjective.trim()
: objective || undefined,
objective: resolvedObjective,
context: context?.trim() ? context.trim() : undefined,
emotion:
emotion?.title && emotion?.description
? `${emotion.title} : ${emotion.description}`
: undefined,
style: otherStyle?.trim() ? otherStyle.trim() : style || undefined,
style: resolvedStyle,
audience: audience?.trim() ? audience.trim() : undefined,
structure:
(customStructure &&
@@ -174,12 +206,14 @@ const CreateLyricsWithAi = () => {
rhymes: rhymes || undefined,
};
}, [
shouldUseOtherObjective,
persistedOtherObjective,
objective,
otherObjective,
shouldUseOtherStyle,
persistedOtherStyle,
context,
emotion,
style,
otherStyle,
audience,
parsedStructure,
rhymes,
@@ -191,9 +225,7 @@ const CreateLyricsWithAi = () => {
case 0: {
const hasObjective =
typeof objective === "string" && objective.length > 0;
const hasOther =
typeof otherObjective === "string" &&
otherObjective.trim().length > 0;
const hasOther = trimmedOtherObjective.length > 0;
return !(hasObjective || hasOther);
}
case 1: {
@@ -209,8 +241,7 @@ const CreateLyricsWithAi = () => {
}
case 3: {
const hasStyle = typeof style === "string" && style.length > 0;
const hasOther =
typeof otherStyle === "string" && otherStyle.trim().length > 0;
const hasOther = trimmedOtherStyle.length > 0;
return !(hasStyle || hasOther);
}
case 4: {
@@ -233,11 +264,11 @@ const CreateLyricsWithAi = () => {
}, [
selectedIndex,
objective,
otherObjective,
trimmedOtherObjective,
context,
emotion,
style,
otherStyle,
trimmedOtherStyle,
audience,
structure,
rhymes,
@@ -257,11 +288,11 @@ const CreateLyricsWithAi = () => {
config: { structure: chosenStructure },
selections: {
objective,
otherObjective,
otherObjective: persistedOtherObjective,
context,
emotion,
style,
otherStyle,
otherStyle: persistedOtherStyle,
audience,
structure,
parsedStructure,
@@ -433,11 +464,11 @@ const CreateLyricsWithAi = () => {
config={lyricsConfig}
selections={{
objective,
otherObjective,
otherObjective: persistedOtherObjective,
context,
emotion,
style,
otherStyle,
otherStyle: persistedOtherStyle,
audience,
structure,
parsedStructure,