filter on lyrics for bloking unwanted content, tickets fix

This commit is contained in:
Thomas Demirdjian
2025-09-08 15:48:29 +02:00
parent 987388c501
commit a3dc4f89b7
22 changed files with 1386 additions and 126 deletions
+59 -23
View File
@@ -25,8 +25,9 @@ const GeneratingSong = () => {
const progressTimerRef = useRef(null);
const navigatedRef = useRef(false);
const isFocused = useIsFocused();
const lastConfigKeyRef = useRef(null);
const askedRef = useRef(false);
const callingRef = useRef(false);
const localStartRef = useRef(null);
// project loaded from provider
@@ -39,26 +40,49 @@ const GeneratingSong = () => {
progressTimerRef.current = null;
}
};
if (selectedProject?.musicStatus === "GENERATED") {
const status = selectedProject?.musicStatus;
if (status !== "GENERATING") {
// Reset local start when leaving generating state
localStartRef.current = null;
}
if (status === "GENERATED") {
setProgress(100);
clearTimer();
return () => clearTimer();
}
const resolveStartDate = () => {
const gs = selectedProject?.generationStartAt;
if (gs?.toDate) return gs.toDate();
if (gs) return new Date(gs);
if (status === "GENERATING") {
if (!localStartRef.current) localStartRef.current = new Date();
return localStartRef.current;
}
return null;
};
const update = () => {
const startDate = selectedProject?.generationStartAt?.toDate
? selectedProject.generationStartAt.toDate()
: new Date(selectedProject?.generationStartAt || Date.now());
const startDate = resolveStartDate();
if (!startDate) {
setProgress(0);
return;
}
const elapsed = moment().diff(moment(startDate));
const raw = Math.floor((elapsed / totalMs) * 100);
// While status is GENERATING, block visual progress at 99%
const pct = Math.max(0, Math.min(99, raw));
setProgress(pct);
};
update();
clearTimer();
progressTimerRef.current = setInterval(update, 1000);
return () => clearTimer();
}, [selectedProject?.musicStatus]);
}, [selectedProject?.musicStatus, selectedProject?.generationStartAt]);
// Auto navigate to SongReady when generation completed
useEffect(() => {
@@ -76,7 +100,7 @@ const GeneratingSong = () => {
title: cfg?.title || "",
lyrics: Array.isArray(cfg?.lyrics) ? cfg.lyrics : [],
genres: Array.isArray(cfg?.genres) ? cfg.genres : [],
voice: cfg?.voice || "",
voice: Array.isArray(cfg?.voice) ? cfg.voice : [],
instruments: Array.isArray(cfg?.instruments) ? cfg.instruments : [],
tempo: cfg?.tempo || "",
};
@@ -131,37 +155,49 @@ const GeneratingSong = () => {
}
}
// Trigger generation only when focused; ask once per config
// Ensure we never call generation more than once concurrently
const startMusicGenerationOnce = React.useCallback(() => {
if (callingRef.current) return;
callingRef.current = true;
startMusicGeneration()
.catch(() => {})
.finally(() => {
// Keep locked while status transitions to GENERATING; will be prevented by guards
setTimeout(() => {
callingRef.current = false;
}, 500);
});
}, []);
// Trigger generation only when focused; ask once while idle
useEffect(() => {
if (!isFocused) return;
const status = selectedProject?.musicStatus;
const titleOk = !!selectedProject?.title;
// Idle if not actively generating or generated (ignore stale taskId)
const isIdle =
status == null ||
status === "" ||
status === "PENDING" ||
status === "READY";
const key = JSON.stringify(effectiveConfig || {});
if (lastConfigKeyRef.current !== key) {
lastConfigKeyRef.current = key;
askedRef.current = false;
}
const canAsk =
!!selectedProject?.title && selectedProject?.musicStatus !== "GENERATING";
if (canAsk && !askedRef.current) {
if (titleOk && isIdle && !askedRef.current) {
askedRef.current = true;
Alert.alert("Attention", "Une génération va être lancée. Continuer ?", [
{
text: "Non",
style: "cancel",
onPress: () => {
askedRef.current = false;
},
},
{
text: "Oui",
onPress: () => startMusicGeneration(),
},
{ text: "Oui", onPress: () => startMusicGenerationOnce() },
]);
}
}, [
isFocused,
selectedProject?.title,
selectedProject?.musicStatus,
effectiveConfig,
]);
return (