2023-09-20 17:39:17 +00:00
|
|
|
|
import {
|
2023-10-12 15:20:46 +00:00
|
|
|
|
Box,
|
|
|
|
|
Link,
|
|
|
|
|
Typography,
|
2023-10-19 10:34:48 +00:00
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme
|
2023-09-20 17:39:17 +00:00
|
|
|
|
} from "@mui/material";
|
2023-10-19 10:34:48 +00:00
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-19 10:34:48 +00:00
|
|
|
|
import { questionStore, updateQuestionsList } from "@root/questions";
|
2023-10-01 12:10:12 +00:00
|
|
|
|
import { CropModal } from "@ui_kit/Modal/CropModal";
|
2023-10-19 10:34:48 +00:00
|
|
|
|
import { AnswerDraggableList } from "../AnswerDraggableList";
|
|
|
|
|
import ButtonsOptions from "../ButtonsOptions";
|
2023-10-01 12:10:12 +00:00
|
|
|
|
import { UploadImageModal } from "../UploadImage/UploadImageModal";
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-09-25 13:43:15 +00:00
|
|
|
|
import { EnterIcon } from "../../../assets/icons/questionsPage/enterIcon";
|
2023-03-30 18:39:59 +00:00
|
|
|
|
import SwitchAnswerOptionsPict from "./switchOptionsPict";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-10-19 10:34:48 +00:00
|
|
|
|
import AddOrEditImageButton from "@ui_kit/AddOrEditImageButton";
|
2023-10-12 15:20:46 +00:00
|
|
|
|
import { produce } from "immer";
|
2023-10-19 10:34:48 +00:00
|
|
|
|
import type { QuizQuestionImages } from "../../../model/questionTypes/images";
|
2023-10-21 13:16:57 +00:00
|
|
|
|
import { openCropModal } from "@root/cropModal";
|
2023-10-03 14:03:57 +00:00
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
interface Props {
|
2023-10-12 15:20:46 +00:00
|
|
|
|
totalIndex: number;
|
2023-08-24 11:09:47 +00:00
|
|
|
|
}
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
export default function OptionsPicture({ totalIndex }: Props) {
|
2023-10-19 10:34:48 +00:00
|
|
|
|
const [isUploadImageModalOpen, setIsUploadImageModalOpen] = useState(false);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
|
|
|
|
const quizId = Number(useParams().quizId);
|
|
|
|
|
const [switchState, setSwitchState] = useState("setting");
|
|
|
|
|
const { listQuestions } = questionStore();
|
|
|
|
|
const question = listQuestions[quizId][totalIndex] as QuizQuestionImages;
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
};
|
2023-03-30 18:39:59 +00:00
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const uploadImage = (files: FileList | null) => {
|
|
|
|
|
if (files?.length) {
|
|
|
|
|
const [file] = Array.from(files);
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const clonedContent = { ...question.content };
|
2023-10-21 13:16:57 +00:00
|
|
|
|
|
|
|
|
|
const url = URL.createObjectURL(file);
|
|
|
|
|
clonedContent.variants[currentIndex].extendedText = url;
|
|
|
|
|
clonedContent.variants[currentIndex].originalImageUrl = url;
|
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
|
|
|
|
content: clonedContent,
|
|
|
|
|
});
|
2023-10-01 12:10:12 +00:00
|
|
|
|
|
2023-10-19 10:34:48 +00:00
|
|
|
|
setIsUploadImageModalOpen(false);
|
2023-10-21 13:16:57 +00:00
|
|
|
|
openCropModal(
|
|
|
|
|
question.content.variants[currentIndex]?.extendedText,
|
|
|
|
|
question.content.variants[currentIndex]?.originalImageUrl,
|
|
|
|
|
);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const addNewAnswer = () => {
|
|
|
|
|
const answerNew = question.content.variants.slice();
|
2023-10-21 13:16:57 +00:00
|
|
|
|
answerNew.push({ answer: "", hints: "", extendedText: "", originalImageUrl: "" });
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
|
|
|
|
content: { ...question.content, variants: answerNew },
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box sx={{ padding: "20px" }}>
|
|
|
|
|
<AnswerDraggableList
|
|
|
|
|
variants={question.content.variants}
|
|
|
|
|
totalIndex={totalIndex}
|
|
|
|
|
additionalContent={(variant, index) => (
|
|
|
|
|
<>
|
|
|
|
|
{!isMobile && (
|
2023-10-19 10:34:48 +00:00
|
|
|
|
<AddOrEditImageButton
|
|
|
|
|
imageSrc={variant.extendedText}
|
|
|
|
|
onImageClick={() => {
|
2023-10-21 13:16:57 +00:00
|
|
|
|
if (!("originalImageUrl" in variant)) return;
|
|
|
|
|
|
2023-10-19 10:34:48 +00:00
|
|
|
|
setCurrentIndex(index);
|
2023-10-21 13:16:57 +00:00
|
|
|
|
if (variant.extendedText) {
|
|
|
|
|
return openCropModal(
|
|
|
|
|
variant.extendedText,
|
|
|
|
|
variant.originalImageUrl
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-10-19 10:34:48 +00:00
|
|
|
|
|
|
|
|
|
setIsUploadImageModalOpen(true);
|
|
|
|
|
}}
|
|
|
|
|
onPlusClick={() => {
|
2023-10-12 15:20:46 +00:00
|
|
|
|
setCurrentIndex(index);
|
2023-10-19 10:34:48 +00:00
|
|
|
|
setIsUploadImageModalOpen(true);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
}}
|
2023-10-19 10:34:48 +00:00
|
|
|
|
sx={{ mx: "10px" }}
|
|
|
|
|
/>
|
2023-10-12 15:20:46 +00:00
|
|
|
|
)}
|
|
|
|
|
</>
|
2023-10-01 12:10:12 +00:00
|
|
|
|
)}
|
2023-10-12 15:20:46 +00:00
|
|
|
|
additionalMobile={(variant, index) => (
|
|
|
|
|
<>
|
|
|
|
|
{isMobile && (
|
2023-10-19 10:34:48 +00:00
|
|
|
|
<AddOrEditImageButton
|
|
|
|
|
imageSrc={variant.extendedText}
|
|
|
|
|
onImageClick={() => {
|
2023-10-21 13:16:57 +00:00
|
|
|
|
if (!("originalImageUrl" in variant)) return;
|
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
setCurrentIndex(index);
|
2023-10-21 13:16:57 +00:00
|
|
|
|
if (variant.extendedText) {
|
|
|
|
|
return openCropModal(
|
|
|
|
|
variant.extendedText,
|
|
|
|
|
variant.originalImageUrl
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-10-19 10:34:48 +00:00
|
|
|
|
|
|
|
|
|
setIsUploadImageModalOpen(true);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
}}
|
2023-10-19 10:34:48 +00:00
|
|
|
|
onPlusClick={() => {
|
|
|
|
|
setCurrentIndex(index);
|
|
|
|
|
setIsUploadImageModalOpen(true);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
}}
|
2023-10-19 10:34:48 +00:00
|
|
|
|
sx={{ m: "8px", width: "auto" }}
|
|
|
|
|
/>
|
2023-10-12 15:20:46 +00:00
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<UploadImageModal
|
2023-10-19 10:34:48 +00:00
|
|
|
|
open={isUploadImageModalOpen}
|
|
|
|
|
onClose={() => setIsUploadImageModalOpen(false)}
|
2023-10-12 15:20:46 +00:00
|
|
|
|
imgHC={uploadImage}
|
|
|
|
|
/>
|
|
|
|
|
<CropModal
|
2023-10-21 13:16:57 +00:00
|
|
|
|
onSaveImageClick={url => {
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const content = produce(question.content, draft => {
|
|
|
|
|
draft.variants[currentIndex].extendedText = url;
|
|
|
|
|
});
|
|
|
|
|
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
|
|
|
|
content,
|
|
|
|
|
});
|
2023-10-01 12:10:12 +00:00
|
|
|
|
}}
|
2023-10-12 15:20:46 +00:00
|
|
|
|
/>
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
|
|
|
|
<Link
|
|
|
|
|
component="button"
|
|
|
|
|
variant="body2"
|
|
|
|
|
sx={{ color: theme.palette.brightPurple.main }}
|
|
|
|
|
onClick={addNewAnswer}
|
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</Link>
|
|
|
|
|
{isMobile ? null : (
|
|
|
|
|
<>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
lineHeight: "21.33px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
или нажмите Enter
|
|
|
|
|
</Typography>
|
|
|
|
|
<EnterIcon
|
|
|
|
|
style={{
|
|
|
|
|
color: "#7E2AEA",
|
|
|
|
|
fontSize: "24px",
|
|
|
|
|
marginLeft: "6px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2023-09-21 07:00:08 +00:00
|
|
|
|
</Box>
|
2023-10-12 15:20:46 +00:00
|
|
|
|
</Box>
|
|
|
|
|
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
|
|
|
|
<SwitchAnswerOptionsPict switchState={switchState} totalIndex={totalIndex} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-08-24 11:09:47 +00:00
|
|
|
|
}
|