fix write lyrics flow

This commit is contained in:
2025-10-23 17:04:33 +02:00
parent feb8d99534
commit 2819b959a0
2 changed files with 22 additions and 71 deletions
+3 -17
View File
@@ -5,12 +5,12 @@ import React, { useCallback, useEffect, useRef, useState } from "react";
import { Image, Platform, Pressable, Text, View } from "react-native"; import { Image, Platform, Pressable, Text, View } from "react-native";
import { responsiveHeight } from "react-native-responsive-dimensions"; import { responsiveHeight } from "react-native-responsive-dimensions";
import { background, icons } from "../../assets"; import { background, icons } from "../../assets";
import BorderGradientButton from "../../components/BorderGradientButton"; import alert from "../../components/Alert";
import GradientButton from "../../components/GradientButton"; import GradientButton from "../../components/GradientButton";
import ValidateModal from "../../components/modal/ValidateModal"; import ValidateModal from "../../components/modal/ValidateModal";
import MusicLandHeader from "../../components/MusicLandHeader"; import MusicLandHeader from "../../components/MusicLandHeader";
import Slider from "../../components/Slider"; import Slider from "../../components/Slider";
import alert from "../../components/Alert"; import { isWeb } from "../../hooks/useLayoutType";
import useSharedAudioPlayer from "../../hooks/useSharedAudioPlayer"; import useSharedAudioPlayer from "../../hooks/useSharedAudioPlayer";
import Page from "../../layouts/Page"; import Page from "../../layouts/Page";
import { Routes } from "../../navigation"; import { Routes } from "../../navigation";
@@ -18,7 +18,6 @@ import { navigate } from "../../navigation/NavigationService";
import { useUser } from "../../providers/UserDataProvider"; import { useUser } from "../../providers/UserDataProvider";
import { Palette, Style } from "../../styles"; import { Palette, Style } from "../../styles";
import { gutters, size } from "../../styles/Style"; import { gutters, size } from "../../styles/Style";
import { isWeb } from "../../hooks/useLayoutType";
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader"; import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
const SongReady = () => { const SongReady = () => {
@@ -360,9 +359,7 @@ const SongReady = () => {
height: 18, height: 18,
borderRadius: 9, borderRadius: 9,
borderWidth: 2, borderWidth: 2,
borderColor: isSelected borderColor: isSelected ? Palette.primary : "white",
? Palette.primary
: "white",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
}} }}
@@ -394,17 +391,6 @@ const SongReady = () => {
gap: 12, gap: 12,
}} }}
> >
<BorderGradientButton
title="Regénérer"
icon={icons.stars}
onPress={async () => {
try {
await player0?.pause?.();
await player1?.pause?.();
} catch {}
navigate(Routes.ComposeSong);
}}
/>
<GradientButton <GradientButton
title="Choisir ce morceau" title="Choisir ce morceau"
onPress={handleChooseTrack} onPress={handleChooseTrack}
+13 -48
View File
@@ -1,5 +1,5 @@
import React, { useMemo, useRef, useState } from "react"; import React, { useMemo, useState } from "react";
import { Dimensions, FlatList, Platform, View } from "react-native"; import { Platform, View } from "react-native";
import { responsiveHeight } from "react-native-responsive-dimensions"; import { responsiveHeight } from "react-native-responsive-dimensions";
import { background, icons } from "../../assets"; import { background, icons } from "../../assets";
import GradientButton from "../../components/GradientButton"; import GradientButton from "../../components/GradientButton";
@@ -21,16 +21,10 @@ import SongStyle from "./SongStyle";
import SongTo from "./SongTo"; import SongTo from "./SongTo";
import SpecificityContext from "./SpecificityContext"; import SpecificityContext from "./SpecificityContext";
const { width: windowWidth } = Dimensions.get("window");
const CreateLyricsWithAi = () => { const CreateLyricsWithAi = () => {
const { selectedProject, updateProjectData } = useUser(); const { selectedProject, updateProjectData } = useUser();
const hasLyrics = selectedProject?.hasLyrics === true; const hasLyrics = selectedProject?.hasLyrics === true;
const scrollRef = useRef(null);
const [selectedIndex, setSelectedIndex] = useState(hasLyrics ? 5 : 0); const [selectedIndex, setSelectedIndex] = useState(hasLyrics ? 5 : 0);
const [progress, setProgress] = useState(16);
const [parentLayout, setParentLayout] = useState(null);
const containerWidth = parentLayout?.width || windowWidth || 1;
// Collected state across steps // Collected state across steps
const [objective, setObjective] = useState(null); // from Goals list const [objective, setObjective] = useState(null); // from Goals list
@@ -200,6 +194,11 @@ const CreateLyricsWithAi = () => {
} }
}, [hasLyrics]); }, [hasLyrics]);
const progress = useMemo(
() => 16 + selectedIndex * 9,
[selectedIndex]
);
const lyricsConfig = useMemo(() => { const lyricsConfig = useMemo(() => {
const resolvedObjective = shouldUseOtherObjective const resolvedObjective = shouldUseOtherObjective
? persistedOtherObjective || undefined ? persistedOtherObjective || undefined
@@ -435,28 +434,7 @@ const CreateLyricsWithAi = () => {
}, },
]; ];
const getItemLayout = React.useCallback( const currentStep = steps[selectedIndex];
(_, index) => ({
length: containerWidth,
offset: containerWidth * index,
index,
}),
[containerWidth]
);
// Sync scroll position and progress with selectedIndex
React.useEffect(() => {
if (!parentLayout?.height) return;
try {
const nextProgress = 16 + selectedIndex * 9;
setProgress(nextProgress);
scrollRef.current?.scrollToIndex?.({
index: selectedIndex,
animated: true,
viewPosition: 0,
});
} catch (_) {}
}, [selectedIndex, parentLayout?.height, containerWidth]);
return ( return (
<Page <Page
@@ -479,31 +457,18 @@ const CreateLyricsWithAi = () => {
> >
<View <View
style={{ flex: 1 }} style={{ flex: 1 }}
onLayout={(e) => setParentLayout(e.nativeEvent.layout)}
> >
<FlatList {currentStep ? (
ref={scrollRef}
data={steps}
keyExtractor={(item) => item.key}
horizontal
pagingEnabled
scrollEnabled={false}
showsHorizontalScrollIndicator={false}
initialScrollIndex={selectedIndex}
getItemLayout={getItemLayout}
style={{ width: containerWidth }}
renderItem={({ item }) => (
<View <View
key={currentStep.key}
style={{ style={{
width: containerWidth, flex: 1,
height: parentLayout?.height,
paddingHorizontal: gutters, paddingHorizontal: gutters,
}} }}
> >
{item.render()} {currentStep.render()}
</View> </View>
)} ) : null}
/>
</View> </View>
{selectedIndex !== 8 && ( {selectedIndex !== 8 && (
<GradientButton <GradientButton