fix tickets

This commit is contained in:
Thomas Demirdjian
2025-10-03 16:19:48 +02:00
parent a1d00b8cf6
commit f3229be1f0
13 changed files with 273 additions and 77 deletions
+67 -11
View File
@@ -1,13 +1,12 @@
import { View, Text, Pressable, Image, Platform } from "react-native";
import React, { useEffect, useState } from "react";
import { View, Text, Image, Platform, Alert } from "react-native";
import React, { useEffect, useRef, useState } from "react";
import { Palette, Style } from "../../styles";
import { BlurView } from "expo-blur";
import { ai, icons } from "../../assets";
import { size } from "../../styles/Style";
import { ai } from "../../assets";
import ProgressBar from "../../components/ProgressBar";
import { FONT_FAMILY } from "../../styles/Fonts";
import GradientButton from "../../components/GradientButton";
import { goBack, navigate } from "../../navigation/NavigationService";
import { navigate } from "../../navigation/NavigationService";
import { Routes } from "../../navigation";
import firebase from "../../config/firebase";
import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
@@ -18,6 +17,8 @@ const CreatingLyrics = ({ active, config, selections }) => {
const [called, setCalled] = useState(false);
const [result, setResult] = useState(null);
const [saved, setSaved] = useState(false);
const [error, setError] = useState(null);
const hasShownErrorAlert = useRef(false);
const { setIsLoading } = useMinuit();
const { updateProjectData } = useUser();
@@ -28,6 +29,8 @@ const CreatingLyrics = ({ active, config, selections }) => {
setResult(null);
setProgress(0);
setSaved(false);
setError(null);
hasShownErrorAlert.current = false;
}
}, [active]);
@@ -52,6 +55,9 @@ const CreatingLyrics = ({ active, config, selections }) => {
try {
setCalled(true);
await setIsLoading(true);
console.log("🚀 [CreatingLyrics] Lancement de la génération", {
platform: Platform.OS,
});
const callable = firebase
.functions()
.httpsCallable("lyrics-generateLyrics");
@@ -66,8 +72,22 @@ const CreatingLyrics = ({ active, config, selections }) => {
});
setResult(data);
setProgress(100);
console.log("✨ [CreatingLyrics] Génération réussie");
} catch (e) {
console.log(e);
console.error("🔥 [CreatingLyrics] Erreur de génération", e);
const rawMessage = typeof e?.message === "string" ? e.message : "";
const cleanedMessage = rawMessage.replace(
/^functions error: \w+-\w+:\s*/i,
"",
);
setError({
message:
cleanedMessage?.length > 0
? cleanedMessage
: "Une erreur est survenue lors de la génération des paroles.",
code: e?.code,
details: e?.details,
});
} finally {
await setIsLoading(false);
}
@@ -85,6 +105,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
if (saved) return;
setSaved(true);
await setIsLoading(true);
console.log("💾 [CreatingLyrics] Sauvegarde automatique des paroles");
await updateProjectData({
title: result?.title || "",
lyrics: Array.isArray(result?.lyrics) ? result.lyrics : [],
@@ -95,13 +116,13 @@ const CreatingLyrics = ({ active, config, selections }) => {
});
navigate(Routes.Lyrics);
} catch (e) {
console.log("Auto save generated lyrics error", e?.message);
console.error("⚠️ [CreatingLyrics] Erreur lors de la sauvegarde", e);
} finally {
await setIsLoading(false);
}
};
if (active && result && progress >= 100 && !saved) {
if (active && result && progress >= 100 && !saved && !error) {
autoSaveAndGo();
}
}, [
@@ -109,12 +130,39 @@ const CreatingLyrics = ({ active, config, selections }) => {
result,
progress,
saved,
error,
setIsLoading,
updateProjectData,
config,
selections,
]);
useEffect(() => {
if (error && !hasShownErrorAlert.current) {
hasShownErrorAlert.current = true;
const redirect = () => {
console.log("↩️ [CreatingLyrics] Retour à WritingLyrics après erreur");
navigate(Routes.WritingLyrics);
};
Alert.alert(
"Brief à reformuler",
error.message,
[
{
text: "OK",
onPress: redirect,
},
],
{ cancelable: false },
);
if (Platform.OS === "web") {
redirect();
}
}
}, [error]);
return (
<View
style={{
@@ -169,7 +217,9 @@ const CreatingLyrics = ({ active, config, selections }) => {
textAlign: "center",
}}
>
Ton texte est{"\n"}en cours de création
{error
? "Impossible de générer les paroles"
: "Ton texte est\nen cours de création"}
</Text>
<View style={{ alignItems: "center", gap: 16 }}>
<ProgressBar gradient progress={progress} />
@@ -183,7 +233,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
{progress}%
</Text>
</View>
{!saved && (
{!saved && result && !error && (
<GradientButton
title="Découvrir mon texte"
containerStyle={{
@@ -195,6 +245,9 @@ const CreatingLyrics = ({ active, config, selections }) => {
if (saved) return;
setSaved(true);
await setIsLoading(true);
console.log(
"📄 [CreatingLyrics] Consultation manuelle du texte",
);
await updateProjectData({
title: result?.title || "",
lyrics: Array.isArray(result?.lyrics)
@@ -206,7 +259,10 @@ const CreatingLyrics = ({ active, config, selections }) => {
});
navigate(Routes.Lyrics);
} catch (e) {
console.log("Save generated lyrics error", e?.message);
console.error(
"⚠️ [CreatingLyrics] Erreur lors de l'ouverture manuelle",
e,
);
} finally {
await setIsLoading(false);
}