continue flow integartion
This commit is contained in:
+111
-10
@@ -1,5 +1,5 @@
|
||||
import { View, Text, ScrollView } from "react-native";
|
||||
import React, { useState } from "react";
|
||||
import { View, Text, ScrollView, Alert } from "react-native";
|
||||
import React, { useMemo, useState, useCallback } from "react";
|
||||
import Page from "../../layouts/Page";
|
||||
import MusicLandHeader from "../../components/MusicLandHeader";
|
||||
import { goBack, navigate } from "../../navigation/NavigationService";
|
||||
@@ -10,9 +10,92 @@ import { Routes } from "../../navigation";
|
||||
import CustomInput from "./components/CustomInput";
|
||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||
import ItemContainer from "../../components/ItemContainer/ItemContainer";
|
||||
import { useRoute } from "@react-navigation/native";
|
||||
import firebase from "../../config/firebase";
|
||||
import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
|
||||
|
||||
const Lyrics = () => {
|
||||
const Lyrics = ({ navigation }) => {
|
||||
const [containerLayout, setContainerLayout] = useState(null);
|
||||
const route = useRoute();
|
||||
const lyricsData = route?.params?.lyricsData;
|
||||
const config = route?.params?.config;
|
||||
const selections = route?.params?.selections;
|
||||
const { setIsLoading } = useMinuit();
|
||||
|
||||
const initial = useMemo(() => {
|
||||
if (!lyricsData || !lyricsData?.success) return {};
|
||||
const title = lyricsData?.title || "";
|
||||
const sections = Array.isArray(lyricsData?.lyrics) ? lyricsData.lyrics : [];
|
||||
const couplets = sections
|
||||
.filter((s) => (s?.type || "").toLowerCase().includes("couplet"))
|
||||
.map((s) => s?.lyrics || "");
|
||||
const refrains = sections
|
||||
.filter((s) => (s?.type || "").toLowerCase().includes("refrain"))
|
||||
.map((s) => s?.lyrics || "");
|
||||
return {
|
||||
title,
|
||||
couplet: couplets.join("\n\n"),
|
||||
refrain: refrains.join("\n\n"),
|
||||
};
|
||||
}, [lyricsData]);
|
||||
|
||||
const [titleValue, setTitleValue] = useState(initial.title || "");
|
||||
const [coupletValue, setCoupletValue] = useState(initial.couplet || "");
|
||||
const [refrainValue, setRefrainValue] = useState(initial.refrain || "");
|
||||
|
||||
// Plus d'appel direct à la cloud function ici: on retourne à l'étape précédente
|
||||
const regenerate = useCallback(() => {
|
||||
navigate(Routes.CreateLyricsWithAi, { regenerateKey: Date.now() });
|
||||
}, []);
|
||||
|
||||
const sanitize = (obj) => {
|
||||
if (obj === undefined) return null;
|
||||
if (obj === null) return null;
|
||||
if (Array.isArray(obj)) return obj.map((v) => sanitize(v));
|
||||
if (typeof obj === "object") {
|
||||
const out = {};
|
||||
Object.keys(obj).forEach((k) => {
|
||||
const v = obj[k];
|
||||
if (v === undefined) return; // omit undefined
|
||||
out[k] = sanitize(v);
|
||||
});
|
||||
return out;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
const onValidate = useCallback(async () => {
|
||||
try {
|
||||
await setIsLoading(true);
|
||||
const user = firebase.auth().currentUser;
|
||||
const payload = {
|
||||
title: titleValue?.trim() || "",
|
||||
lyrics: {
|
||||
couplet: coupletValue || "",
|
||||
refrain: refrainValue || "",
|
||||
},
|
||||
config: sanitize(config),
|
||||
selections: sanitize(selections),
|
||||
userId: user ? user.uid : null,
|
||||
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||
};
|
||||
await firebase.firestore().collection("projects").add(payload);
|
||||
navigate(Routes.Studio);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
Alert.alert("Erreur", "Échec de l'enregistrement dans le projet.");
|
||||
} finally {
|
||||
await setIsLoading(false);
|
||||
}
|
||||
}, [
|
||||
titleValue,
|
||||
coupletValue,
|
||||
refrainValue,
|
||||
config,
|
||||
selections,
|
||||
setIsLoading,
|
||||
]);
|
||||
|
||||
return (
|
||||
<Page headerType="NONE">
|
||||
@@ -34,7 +117,13 @@ const Lyrics = () => {
|
||||
flexGrow: 1,
|
||||
}}
|
||||
>
|
||||
<CustomInput label="Titre" placeholder="Titre" height={45} />
|
||||
<CustomInput
|
||||
label="Titre"
|
||||
placeholder="Titre"
|
||||
height={45}
|
||||
value={titleValue}
|
||||
setValue={setTitleValue}
|
||||
/>
|
||||
<View
|
||||
style={{
|
||||
height: 45,
|
||||
@@ -55,8 +144,20 @@ const Lyrics = () => {
|
||||
Introduction instrumentale longue
|
||||
</Text>
|
||||
</View>
|
||||
<CustomInput label="Couplet" placeholder="Couplet" height={225} />
|
||||
<CustomInput label="Refrain" placeholder="Refrain" height={170} />
|
||||
<CustomInput
|
||||
label="Couplet"
|
||||
placeholder="Couplet"
|
||||
height={225}
|
||||
value={coupletValue}
|
||||
setValue={setCoupletValue}
|
||||
/>
|
||||
<CustomInput
|
||||
label="Refrain"
|
||||
placeholder="Refrain"
|
||||
height={170}
|
||||
value={refrainValue}
|
||||
setValue={setRefrainValue}
|
||||
/>
|
||||
</ScrollView>
|
||||
</ItemContainer>
|
||||
</View>
|
||||
@@ -68,11 +169,11 @@ const Lyrics = () => {
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
<BorderGradientButton title="Générer des autres paroles" />
|
||||
<GradientButton
|
||||
title="Valider"
|
||||
onPress={() => navigate(Routes.FinishedWriting)}
|
||||
<BorderGradientButton
|
||||
title="Générer d'autre paroles"
|
||||
onPress={regenerate}
|
||||
/>
|
||||
<GradientButton title="Valider" onPress={onValidate} />
|
||||
</View>
|
||||
</Page>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user