2023-12-12 19:39:21 +00:00
|
|
|
|
import {Box, Typography, ButtonBase, useTheme, IconButton} from "@mui/material";
|
2023-12-01 13:48:25 +00:00
|
|
|
|
import { useQuizViewStore, updateAnswer } from "@root/quizView";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
import { UPLOAD_FILE_TYPES_MAP } from "@ui_kit/QuizPreview/QuizPreviewQuestionTypes/File";
|
|
|
|
|
|
|
|
|
|
import UploadIcon from "@icons/UploadIcon";
|
2023-12-12 19:39:21 +00:00
|
|
|
|
import X from "@icons/CloseBold";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
import type { ChangeEvent } from "react";
|
|
|
|
|
import type { QuizQuestionFile } from "../../../model/questionTypes/file";
|
2023-12-12 19:39:21 +00:00
|
|
|
|
import {DragEvent} from "react";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
|
|
type FileProps = {
|
2023-12-03 10:48:00 +00:00
|
|
|
|
currentQuestion: QuizQuestionFile;
|
2023-11-30 17:39:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
export const File = ({ currentQuestion }: FileProps) => {
|
2023-12-01 13:48:25 +00:00
|
|
|
|
const { answers } = useQuizViewStore();
|
2023-12-12 14:15:40 +00:00
|
|
|
|
const answer = answers.find(
|
|
|
|
|
({ questionId }) => questionId === currentQuestion.content.id
|
|
|
|
|
)?.answer as string;
|
2023-12-12 19:39:21 +00:00
|
|
|
|
const theme = useTheme();
|
2023-11-30 17:39:57 +00:00
|
|
|
|
const uploadFile = ({ target }: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const file = target.files?.[0];
|
|
|
|
|
|
|
|
|
|
if (file) {
|
2023-12-12 14:15:40 +00:00
|
|
|
|
updateAnswer(
|
|
|
|
|
currentQuestion.content.id,
|
|
|
|
|
`${file.name}|${URL.createObjectURL(file)}`
|
|
|
|
|
);
|
2023-11-30 17:39:57 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
2023-12-03 10:48:00 +00:00
|
|
|
|
<Typography variant="h5">{currentQuestion.title}</Typography>
|
2023-11-30 17:39:57 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
width: "100%",
|
|
|
|
|
marginTop: "20px",
|
2023-12-12 19:39:21 +00:00
|
|
|
|
maxWidth: answer?.split("|")[0] ? "640px" : "550px"
|
2023-11-30 17:39:57 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-13 09:34:52 +00:00
|
|
|
|
{answer?.split("|")[0] && (
|
|
|
|
|
<Box sx={{display: "flex", alignItems: "center", gap: "15px"}}>
|
|
|
|
|
<Typography>Вы загрузили:</Typography>
|
|
|
|
|
<Box sx={{padding: "5px 5px 5px 16px", backgroundColor: theme.palette.brightPurple.main,
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
color: "#FFFFFF",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "15px"
|
|
|
|
|
}}>
|
|
|
|
|
<Typography>
|
|
|
|
|
{answer?.split("|")[0]}
|
|
|
|
|
</Typography>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{p: 0}}
|
|
|
|
|
onClick={() => {updateAnswer(currentQuestion.content.id, "");}}
|
|
|
|
|
>
|
|
|
|
|
<X/>
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{!answer?.split("|")[0] && (
|
|
|
|
|
<ButtonBase component="label" sx={{ justifyContent: "flex-start" }}>
|
|
|
|
|
<input
|
|
|
|
|
onChange={uploadFile}
|
|
|
|
|
hidden
|
|
|
|
|
accept={UPLOAD_FILE_TYPES_MAP[currentQuestion.content.type]}
|
|
|
|
|
multiple
|
|
|
|
|
type="file"
|
|
|
|
|
/>
|
|
|
|
|
<Box
|
|
|
|
|
onDragOver={(event: DragEvent<HTMLDivElement>) => event.preventDefault()}
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "120px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
padding: "33px 44px 33px 55px",
|
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
border: `1px solid ${theme.palette.grey2.main}`,
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<UploadIcon />
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
fontWeight: 500
|
|
|
|
|
}}
|
|
|
|
|
>Добавить видео</Typography>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
lineHeight: "19px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Принимает .mp4 и .mov формат — максимум 100мб
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
</Box>
|
|
|
|
|
</ButtonBase>
|
|
|
|
|
)}
|
|
|
|
|
{answer && currentQuestion.content.type === "picture" && (
|
2023-12-12 14:15:40 +00:00
|
|
|
|
<img
|
|
|
|
|
src={answer.split("|")[1]}
|
|
|
|
|
alt=""
|
|
|
|
|
style={{
|
|
|
|
|
marginTop: "15px",
|
|
|
|
|
maxWidth: "300px",
|
|
|
|
|
maxHeight: "300px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{answer && currentQuestion.content.type === "video" && (
|
|
|
|
|
<video
|
|
|
|
|
src={answer.split("|")[1]}
|
|
|
|
|
style={{
|
|
|
|
|
marginTop: "15px",
|
|
|
|
|
maxWidth: "300px",
|
|
|
|
|
maxHeight: "300px",
|
|
|
|
|
objectFit: "cover",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-11-30 17:39:57 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|