clear last tickets
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Image as ExpoImage } from "expo-image";
|
||||
import React from "react";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { ActivityIndicator, Text, View } from "react-native";
|
||||
import { background } from "../../assets";
|
||||
import GradientButton from "../../components/GradientButton";
|
||||
@@ -11,9 +11,17 @@ import { Routes } from "../../navigation";
|
||||
import { goBack, navigate } from "../../navigation/NavigationService";
|
||||
import { useUserData } from "../../providers/UserDataProvider";
|
||||
import { gutters, Palette, Style } from "../../styles";
|
||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
|
||||
import ProgressBar from "../../components/ProgressBar";
|
||||
const COVER_PROGRESS_MAX = 98;
|
||||
const COVER_PROGRESS_INTERVAL_MS = 500;
|
||||
const COVER_FAKE_DURATION_MS = 2 * 60 * 1000;
|
||||
|
||||
const PhotoCover = () => {
|
||||
const [coverProgress, setCoverProgress] = useState(0);
|
||||
const progressIntervalRef = useRef(null);
|
||||
const progressStartRef = useRef(null);
|
||||
const { selectedProject } = useUserData();
|
||||
const isGenerating = selectedProject?.coverStatus === "GENERATING";
|
||||
const coverGenerationMessage = isWeb
|
||||
@@ -29,6 +37,46 @@ const PhotoCover = () => {
|
||||
coverOptions?.[0]?.finalUrl ||
|
||||
coverOptions?.[0]?.generatedUrl ||
|
||||
null;
|
||||
const coverProgressValue = Math.max(
|
||||
0,
|
||||
Math.min(100, Math.round(coverProgress)),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const clearProgressInterval = () => {
|
||||
if (progressIntervalRef.current) {
|
||||
global.clearInterval(progressIntervalRef.current);
|
||||
progressIntervalRef.current = null;
|
||||
}
|
||||
};
|
||||
|
||||
if (!isGenerating || coverUrl) {
|
||||
clearProgressInterval();
|
||||
progressStartRef.current = null;
|
||||
setCoverProgress(coverUrl ? 100 : 0);
|
||||
return clearProgressInterval;
|
||||
}
|
||||
|
||||
progressStartRef.current = new Date();
|
||||
setCoverProgress(0);
|
||||
clearProgressInterval();
|
||||
progressIntervalRef.current = global.setInterval(() => {
|
||||
const start = progressStartRef.current;
|
||||
if (!start) return;
|
||||
const elapsed = Date.now() - start.getTime();
|
||||
const ratio = Math.max(
|
||||
0,
|
||||
Math.min(1, elapsed / COVER_FAKE_DURATION_MS),
|
||||
);
|
||||
const next = COVER_PROGRESS_MAX * ratio;
|
||||
setCoverProgress((prev) => {
|
||||
if (prev >= COVER_PROGRESS_MAX) return COVER_PROGRESS_MAX;
|
||||
return next >= COVER_PROGRESS_MAX ? COVER_PROGRESS_MAX : next;
|
||||
});
|
||||
}, COVER_PROGRESS_INTERVAL_MS);
|
||||
|
||||
return clearProgressInterval;
|
||||
}, [coverUrl, isGenerating]);
|
||||
|
||||
return (
|
||||
<Page backgroundImg={background.studioBG2} headerType="NONE">
|
||||
@@ -91,6 +139,18 @@ const PhotoCover = () => {
|
||||
Génération en cours.
|
||||
</Text>
|
||||
)}
|
||||
<View style={{ alignItems: "center", gap: 10 }}>
|
||||
<ProgressBar gradient progress={coverProgressValue} />
|
||||
<Text
|
||||
style={{
|
||||
color: Palette.white,
|
||||
fontFamily: FONT_FAMILY.InterRegular,
|
||||
fontSize: 13,
|
||||
}}
|
||||
>
|
||||
{coverProgressValue}%
|
||||
</Text>
|
||||
</View>
|
||||
</>
|
||||
) : (
|
||||
<Text
|
||||
|
||||
Reference in New Issue
Block a user