feat: Add preview_video for sights
This commit is contained in:
@@ -36,7 +36,13 @@ interface UploadMediaDialogProps {
|
||||
media_type: number;
|
||||
}) => void;
|
||||
afterUploadSight?: (id: string) => void;
|
||||
hardcodeType?: "thumbnail" | "watermark_lu" | "watermark_rd" | "image" | null;
|
||||
hardcodeType?:
|
||||
| "thumbnail"
|
||||
| "watermark_lu"
|
||||
| "watermark_rd"
|
||||
| "image"
|
||||
| "video_preview"
|
||||
| null;
|
||||
contextObjectName?: string;
|
||||
contextType?:
|
||||
| "sight"
|
||||
@@ -47,6 +53,7 @@ interface UploadMediaDialogProps {
|
||||
| "station";
|
||||
isArticle?: boolean;
|
||||
articleName?: string;
|
||||
initialFile?: File; // <--- добавлено
|
||||
}
|
||||
|
||||
export const UploadMediaDialog = observer(
|
||||
@@ -60,6 +67,7 @@ export const UploadMediaDialog = observer(
|
||||
|
||||
isArticle,
|
||||
articleName,
|
||||
initialFile, // <--- добавлено
|
||||
}: UploadMediaDialogProps) => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -74,6 +82,17 @@ export const UploadMediaDialog = observer(
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialFile) {
|
||||
setMediaFile(initialFile);
|
||||
setMediaFilename(initialFile.name);
|
||||
setAvailableMediaTypes([2]);
|
||||
setMediaType(2);
|
||||
setMediaUrl(URL.createObjectURL(initialFile));
|
||||
setMediaName(initialFile.name.replace(/\.[^/.]+$/, ""));
|
||||
}
|
||||
}, [initialFile]);
|
||||
|
||||
useEffect(() => {
|
||||
if (fileToUpload) {
|
||||
setMediaFile(fileToUpload);
|
||||
@@ -226,6 +245,10 @@ export const UploadMediaDialog = observer(
|
||||
}
|
||||
}
|
||||
setSuccess(true);
|
||||
// Закрываем модальное окно после успешного сохранения
|
||||
setTimeout(() => {
|
||||
handleClose();
|
||||
}, 1000); // Небольшая задержка, чтобы пользователь увидел сообщение об успехе
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Failed to save media");
|
||||
} finally {
|
||||
@@ -333,10 +356,15 @@ export const UploadMediaDialog = observer(
|
||||
<Box className="flex flex-col gap-2 self-end">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="success"
|
||||
sx={{
|
||||
backgroundColor: isLoading ? "#9e9e9e" : "#4caf50",
|
||||
"&:hover": {
|
||||
backgroundColor: isLoading ? "#9e9e9e" : "#45a049",
|
||||
},
|
||||
}}
|
||||
startIcon={
|
||||
isLoading ? (
|
||||
<CircularProgress size={16} />
|
||||
<CircularProgress size={16} color="inherit" />
|
||||
) : (
|
||||
<Save size={16} />
|
||||
)
|
||||
@@ -344,7 +372,7 @@ export const UploadMediaDialog = observer(
|
||||
onClick={handleSave}
|
||||
disabled={isLoading || (!mediaName && !mediaFilename)}
|
||||
>
|
||||
Сохранить
|
||||
{isLoading ? "Сохранение..." : "Сохранить"}
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user