rev 4
This commit is contained in:
@@ -34,7 +34,7 @@ import cs from "classnames"
|
||||
|
||||
import api, { fetchClient } from "@shared/api"
|
||||
import { useWizard } from "@shared/context/WizardContext"
|
||||
import { useAppSelector } from "@shared/hooks/useAppSelector"
|
||||
import { useTaskProgressState } from "@shared/hooks/useTaskProgressState"
|
||||
import { Badge, Button, CircularProgress } from "@shared/ui"
|
||||
import { StaticLoader } from "@shared/ui/Loader"
|
||||
|
||||
@@ -135,28 +135,30 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
|
||||
})
|
||||
}, [convertMutation, primaryFileKey, projectId])
|
||||
|
||||
const convertNotification = useAppSelector((state) =>
|
||||
convertJobId
|
||||
? state.notifications.items.find((n) => n.job_id === convertJobId)
|
||||
: null,
|
||||
)
|
||||
|
||||
const convertProgressPct = convertNotification?.progress_pct ?? 0
|
||||
const convertMessage = convertNotification?.message ?? "Конвертация видео..."
|
||||
const {
|
||||
progressPct: convertProgressPct,
|
||||
message: convertMessage,
|
||||
status: convertTaskStatus,
|
||||
errorMessage: convertErrorMessage,
|
||||
} = useTaskProgressState({
|
||||
jobId: convertJobId,
|
||||
enabled: !!convertJobId && convertStatus === "converting",
|
||||
defaultMessage: "Конвертация видео...",
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!convertJobId || convertStatus !== "converting") return
|
||||
|
||||
if (convertNotification?.status === "DONE") {
|
||||
if (convertTaskStatus === "DONE") {
|
||||
fetchConvertedFileFromJob(convertJobId)
|
||||
}
|
||||
|
||||
if (convertNotification?.status === "FAILED") {
|
||||
if (convertTaskStatus === "FAILED") {
|
||||
setActiveJob(null)
|
||||
setConvertError(convertNotification?.message ?? "Ошибка конвертации")
|
||||
setConvertError(convertErrorMessage ?? "Ошибка конвертации")
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [convertNotification, convertJobId, convertStatus])
|
||||
}, [convertErrorMessage, convertJobId, convertStatus, convertTaskStatus])
|
||||
|
||||
const fetchConvertedFileFromJob = useCallback(
|
||||
async (jobId: string) => {
|
||||
@@ -165,13 +167,13 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
|
||||
{ params: { path: { job_id: jobId } } },
|
||||
)
|
||||
const outputData = taskStatus?.output_data as {
|
||||
file_id?: string
|
||||
file_path?: string
|
||||
file_url?: string
|
||||
} | null
|
||||
|
||||
if (outputData?.file_path && outputData?.file_url) {
|
||||
if (outputData?.file_id && outputData?.file_path) {
|
||||
const convertedName = outputData.file_path.split("/").pop() ?? null
|
||||
setFileKey(outputData.file_path, outputData.file_url, convertedName)
|
||||
setFileKey(outputData.file_path, outputData.file_id, convertedName)
|
||||
setActiveJob(null)
|
||||
}
|
||||
},
|
||||
@@ -181,7 +183,7 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
|
||||
/* ---- Handlers ---- */
|
||||
|
||||
const handleReplace = () => {
|
||||
setFileKey("", "", null)
|
||||
setFileKey(null, null, null)
|
||||
goToStep("upload")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user