import { useParams } from "react-router-dom"; import { Typography, Box, useTheme, ButtonBase } from "@mui/material"; import UploadBox from "@ui_kit/UploadBox"; import { CropModal } from "@ui_kit/Modal/CropModal"; import UploadIcon from "../../../assets/icons/UploadIcon"; import * as React from "react"; import { questionStore, updateQuestionsList } from "@root/questions"; import { UploadImageModal } from "./UploadImageModal"; import type { DragEvent } from "react"; import type { QuizQuestionImages } from "../../../model/questionTypes/images"; import { openCropModal } from "@root/cropModal"; type UploadImageProps = { totalIndex: number; }; export default function UploadImage({ totalIndex }: UploadImageProps) { const quizId = Number(useParams().quizId); const theme = useTheme(); const [open, setOpen] = React.useState(false); const { listQuestions } = questionStore(); const question = listQuestions[quizId][totalIndex] as QuizQuestionImages; const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); const imgHC = (files: FileList | null) => { if (files?.length) { const [file] = Array.from(files); updateQuestionsList(quizId, totalIndex, { content: { ...question.content, back: URL.createObjectURL(file), }, }); handleClose(); openCropModal(question.content.back, question.content.back); } }; const handleDrop = (event: DragEvent) => { event.preventDefault(); event.stopPropagation(); imgHC(event.dataTransfer.files); }; return ( Загрузить изображение } text="5 MB максимум" /> ); }