import { QuizQuestionVariant } from "@model/questionTypes/variant"; import { Box, ButtonBase, Typography, useTheme } from "@mui/material"; import { openCropModal } from "@root/cropModal"; import { setQuestionBackgroundImage, setQuestionOriginalBackgroundImage } from "@root/questions/actions"; import { CropModal } from "@ui_kit/Modal/CropModal"; import UploadBox from "@ui_kit/UploadBox"; import { useState, type DragEvent } from "react"; import UploadIcon from "../../../assets/icons/UploadIcon"; import { UploadImageModal } from "./UploadImageModal"; type UploadImageProps = { question: QuizQuestionVariant; }; export default function UploadImage({ question }: UploadImageProps) { const theme = useTheme(); const [isUploadImageModalOpen, setIsUploadImageModalOpen] = useState(false); const handleImageUpload = (files: FileList | null) => { if (!files?.length) return; const [file] = Array.from(files); const url = URL.createObjectURL(file); setQuestionBackgroundImage(question.id, url); setQuestionOriginalBackgroundImage(question.id, url); setIsUploadImageModalOpen(false); openCropModal(url, url); }; const handleDrop = (event: DragEvent) => { event.preventDefault(); event.stopPropagation(); handleImageUpload(event.dataTransfer.files); }; function handleCropModalSaveClick(url: string) { setQuestionBackgroundImage(question.id, url); } return ( Загрузить изображение setIsUploadImageModalOpen(true)} sx={{ width: "100%", maxWidth: "260px", height: "120px", }} > {question.content.back ? question background : } text="5 MB максимум" /> } setIsUploadImageModalOpen(false)} imgHC={handleImageUpload} /> ); }