2024-04-23 14:45:49 +00:00
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { Box, Modal, Typography, useTheme } from "@mui/material";
|
|
|
|
|
|
|
|
|
|
import { UploadFile } from "./UploadFile";
|
|
|
|
|
import { UploadedFile } from "./UploadedFile";
|
|
|
|
|
|
|
|
|
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
|
|
|
|
import { useQuizViewStore } from "@stores/quizView";
|
|
|
|
|
|
|
|
|
|
import { ACCEPT_SEND_FILE_TYPES_MAP } from "@/components/ViewPublicationPage/tools/fileUpload";
|
|
|
|
|
|
|
|
|
|
import type { QuizQuestionFile } from "@model/questionTypes/file";
|
|
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
|
export type ModalWarningType = "errorType" | "errorSize" | "picture" | "video" | "audio" | "document" | null;
|
2024-04-23 14:45:49 +00:00
|
|
|
|
|
|
|
|
|
type FileProps = {
|
|
|
|
|
currentQuestion: QuizQuestionFile;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const File = ({ currentQuestion }: FileProps) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const answers = useQuizViewStore((state) => state.answers);
|
2024-05-31 16:41:18 +00:00
|
|
|
|
const [modalWarningType, setModalWarningType] = useState<ModalWarningType>(null);
|
2024-04-23 14:45:49 +00:00
|
|
|
|
const [isSending, setIsSending] = useState<boolean>(false);
|
|
|
|
|
const isMobile = useRootContainerSize() < 500;
|
|
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
|
const answer = answers.find(({ questionId }) => questionId === currentQuestion.id)?.answer as string;
|
2024-04-23 14:45:49 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
2024-05-31 16:41:18 +00:00
|
|
|
|
<Typography variant="h5" color={theme.palette.text.primary} sx={{ wordBreak: "break-word" }}>
|
2024-04-23 14:45:49 +00:00
|
|
|
|
{currentQuestion.title}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
width: "100%",
|
|
|
|
|
marginTop: "20px",
|
|
|
|
|
maxWidth: answer?.split("|")[0] ? "640px" : "600px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{answer?.split("|")[0] ? (
|
2024-05-31 16:41:18 +00:00
|
|
|
|
<UploadedFile currentQuestion={currentQuestion} setIsSending={setIsSending} />
|
2024-04-23 14:45:49 +00:00
|
|
|
|
) : (
|
|
|
|
|
<UploadFile
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
setModalWarningType={setModalWarningType}
|
|
|
|
|
isSending={isSending}
|
|
|
|
|
setIsSending={setIsSending}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{answer && currentQuestion.content.type === "picture" && (
|
2024-05-31 16:41:18 +00:00
|
|
|
|
<img src={answer.split("|")[1]} style={{ marginTop: "15px", maxWidth: "300px", maxHeight: "300px" }} alt="" />
|
2024-04-23 14:45:49 +00:00
|
|
|
|
)}
|
|
|
|
|
{answer && currentQuestion.content.type === "video" && (
|
|
|
|
|
<video
|
|
|
|
|
src={answer.split("|")[1]}
|
|
|
|
|
style={{
|
|
|
|
|
marginTop: "15px",
|
|
|
|
|
maxWidth: "300px",
|
|
|
|
|
maxHeight: "300px",
|
|
|
|
|
objectFit: "cover",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2024-05-31 16:41:18 +00:00
|
|
|
|
<Modal open={modalWarningType !== null} onClose={() => setModalWarningType(null)}>
|
2024-04-23 14:45:49 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
width: isMobile ? 300 : 400,
|
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
|
borderRadius: 3,
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
p: 4,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CurrentModal status={modalWarningType} />
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const CurrentModal = ({ status }: { status: ModalWarningType }) => {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case null:
|
|
|
|
|
return null;
|
|
|
|
|
case "errorType":
|
|
|
|
|
return <Typography>Выбран некорректный тип файла</Typography>;
|
|
|
|
|
case "errorSize":
|
2024-05-31 16:41:18 +00:00
|
|
|
|
return <Typography>Файл слишком большой. Максимальный размер 50 МБ</Typography>;
|
2024-04-23 14:45:49 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Typography>Допустимые расширения файлов:</Typography>
|
2024-05-31 16:41:18 +00:00
|
|
|
|
<Typography>{ACCEPT_SEND_FILE_TYPES_MAP[status].join(" ")}</Typography>
|
2024-04-23 14:45:49 +00:00
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|