fix: progress

This commit is contained in:
2025-11-03 10:58:18 +01:00
parent ecd19eaa50
commit 460c91f1e6
+25 -13
View File
@@ -18,6 +18,9 @@ import {
segmentRequiresLyrics, segmentRequiresLyrics,
} from "../../utils/songStructure"; } from "../../utils/songStructure";
const FAKE_PROGRESS_MAX = 96;
const PROGRESS_INTERVAL_MS = 250;
const CreatingLyrics = ({ active, config, selections }) => { const CreatingLyrics = ({ active, config, selections }) => {
const [progress, setProgress] = useState(0); const [progress, setProgress] = useState(0);
const [called, setCalled] = useState(false); const [called, setCalled] = useState(false);
@@ -42,20 +45,29 @@ const CreatingLyrics = ({ active, config, selections }) => {
}, [active]); }, [active]);
useEffect(() => { useEffect(() => {
if (active) { if (!active) return undefined;
const interval = setInterval(() => {
setProgress((prevProgress) => {
if (prevProgress >= 100) {
clearInterval(interval);
return 100;
}
return prevProgress + 1;
});
}, 100);
return () => clearInterval(interval); const interval = setInterval(() => {
} setProgress((prevProgress) => {
}, [active]); if (result || error) return prevProgress;
if (prevProgress >= FAKE_PROGRESS_MAX) {
return FAKE_PROGRESS_MAX;
}
const increment =
prevProgress < 60
? 1
: prevProgress < 80
? 0.6
: 0.3;
const next = prevProgress + increment;
return next >= FAKE_PROGRESS_MAX ? FAKE_PROGRESS_MAX : next;
});
}, PROGRESS_INTERVAL_MS);
return () => clearInterval(interval);
}, [active, result, error]);
useEffect(() => { useEffect(() => {
const run = async () => { const run = async () => {