mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
Api2.6 / Delete Job new uses api manager (#532)
Co-authored-by: wil <wil@storyteller.ai>
This commit is contained in:
1 parent
ec066c1e68
commit
5ee4d493c1
2 files changed
+41
-51
No files matched your search
@@ -23,7 +23,6 @@ interface Props {
|
||||
|
||||
export function CompletedCard({ movie, setMovieId }: Props) {
|
||||
useSignals();
|
||||
// console.log(movie);
|
||||
const bucketConfig = useRef<BucketConfig>(new BucketConfig());
|
||||
const [loadError, setLoadError] = useState(false);
|
||||
const downloadLink = `${environmentVariables.values.GOOGLE_API}/vocodes-public${movie.public_bucket_path}`;
|
||||
|
||||
@@ -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 (
|
||||
<button className="flex w-full items-center justify-between px-5 py-3 text-start transition-all duration-150">
|
||||
<div className="flex w-full items-center justify-between px-5 py-3 text-start transition-all duration-150">
|
||||
<div className="flex gap-4">
|
||||
<div className="flex aspect-video w-36 items-center justify-center rounded-lg bg-white/10">
|
||||
<div>
|
||||
{movie.status.status === JobState.STARTED && (
|
||||
<svg
|
||||
className="h-6 w-6 animate-spin text-white"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
></circle>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
></path>
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex h-32 w-32 items-center justify-center rounded-lg bg-white/10">
|
||||
{(movie.status.status === JobState.STARTED ||
|
||||
movie.status.status === JobState.PENDING) && (
|
||||
<FontAwesomeIcon icon={faSpinnerThird} spin size={"2x"} />
|
||||
)}
|
||||
{(movie.status.status === JobState.COMPLETE_FAILURE ||
|
||||
movie.status.status === JobState.ATTEMPT_FAILED) && (
|
||||
<FontAwesomeIcon icon={faCircleExclamation} size={"2x"} />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-col justify-center gap-2">
|
||||
<div className="font-medium">
|
||||
@@ -99,7 +90,7 @@ export function InProgressCard({ movie }: Props) {
|
||||
<div className="pr-5">
|
||||
<Tooltip content="Cancel" position="top">
|
||||
<button
|
||||
onClick={deleteJob}
|
||||
onClick={() => deleteJob(movie)}
|
||||
className="text-xl text-white/50 transition-all duration-150 hover:text-white/90"
|
||||
>
|
||||
<FontAwesomeIcon icon={faClose} />
|
||||
@@ -107,6 +98,6 @@ export function InProgressCard({ movie }: Props) {
|
||||
</Tooltip>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user