diff --git a/app/pages/PageEnigma/comps/GenerateModals/CompletedCard.tsx b/app/pages/PageEnigma/comps/GenerateModals/CompletedCard.tsx index d5a432e5b3..f18a55ba31 100644 --- a/app/pages/PageEnigma/comps/GenerateModals/CompletedCard.tsx +++ b/app/pages/PageEnigma/comps/GenerateModals/CompletedCard.tsx @@ -23,7 +23,6 @@ interface Props { export function CompletedCard({ movie, setMovieId }: Props) { useSignals(); - // console.log(movie); const bucketConfig = useRef(new BucketConfig()); const [loadError, setLoadError] = useState(false); const downloadLink = `${environmentVariables.values.GOOGLE_API}/vocodes-public${movie.public_bucket_path}`; diff --git a/app/pages/PageEnigma/comps/GenerateModals/InProgressCard.tsx b/app/pages/PageEnigma/comps/GenerateModals/InProgressCard.tsx index 73c072553c..7b9f7f0d69 100644 --- a/app/pages/PageEnigma/comps/GenerateModals/InProgressCard.tsx +++ b/app/pages/PageEnigma/comps/GenerateModals/InProgressCard.tsx @@ -1,15 +1,20 @@ import { useCallback } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faClose } from "@fortawesome/pro-solid-svg-icons"; +import { + faClose, + faCircleExclamation, + faSpinnerThird, +} from "@fortawesome/pro-solid-svg-icons"; import { ToastTypes } from "~/enums"; import { addToast } from "~/signals"; -import environmentVariables from "~/Classes/EnvironmentVariables"; import { JobState } from "~/pages/PageEnigma/enums"; import { ActiveJob } from "~/pages/PageEnigma/models"; import { Tooltip } from "~/components"; +import { JobsApi } from "~/Classes/ApiManager"; +import { PollRecentJobs } from "~/hooks/useActiveJobs/utilities"; interface Props { movie: ActiveJob; @@ -19,12 +24,16 @@ function getPercent(status: JobState) { if (status === JobState.STARTED) { return 20; } - if (status === JobState.PENDING) { - return 0; - } - if (status === JobState.COMPLETE_FAILURE) { + if ( + [ + JobState.PENDING, + JobState.COMPLETE_FAILURE, + JobState.ATTEMPT_FAILED, + ].includes(status) + ) { return 0; } + return 100; } @@ -32,52 +41,34 @@ export function InProgressCard({ movie }: Props) { const completePercent = getPercent(movie.status.status as JobState); const completeLength = (600 * completePercent) / 100; - const deleteJob = useCallback(() => { - const endpoint = `${environmentVariables.values.BASE_API}/v1/jobs/job/${movie.job_token}`; + const deleteJob = useCallback(async (movieJob: ActiveJob) => { + const jobsApi = new JobsApi(); - fetch(endpoint, { - method: "DELETE", - headers: { - Accept: "application/json", - }, - credentials: "include", - }) - .then(() => { - addToast(ToastTypes.SUCCESS, "File successfully deleted."); - }) - .catch(() => { - addToast(ToastTypes.ERROR, "Error deleting the file."); - }); - }, [movie]); + const response = await jobsApi.DeleteJobByToken(movieJob.job_token); + if (response.success) { + PollRecentJobs(); + addToast(ToastTypes.SUCCESS, "File successfully deleted."); + return; + } + + addToast( + ToastTypes.ERROR, + response.errorMessage || "Error deleting the file.", + ); + }, []); return ( - + ); }