fix: progress
This commit is contained in:
@@ -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(() => {
|
const interval = setInterval(() => {
|
||||||
setProgress((prevProgress) => {
|
setProgress((prevProgress) => {
|
||||||
if (prevProgress >= 100) {
|
if (result || error) return prevProgress;
|
||||||
clearInterval(interval);
|
if (prevProgress >= FAKE_PROGRESS_MAX) {
|
||||||
return 100;
|
return FAKE_PROGRESS_MAX;
|
||||||
}
|
}
|
||||||
return prevProgress + 1;
|
|
||||||
|
const increment =
|
||||||
|
prevProgress < 60
|
||||||
|
? 1
|
||||||
|
: prevProgress < 80
|
||||||
|
? 0.6
|
||||||
|
: 0.3;
|
||||||
|
|
||||||
|
const next = prevProgress + increment;
|
||||||
|
return next >= FAKE_PROGRESS_MAX ? FAKE_PROGRESS_MAX : next;
|
||||||
});
|
});
|
||||||
}, 100);
|
}, PROGRESS_INTERVAL_MS);
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}
|
}, [active, result, error]);
|
||||||
}, [active]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user