2023-09-20 17:39:17 +00:00
|
|
|
|
import {
|
2023-11-15 18:38:02 +00:00
|
|
|
|
Box,
|
|
|
|
|
Link,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme
|
2023-09-20 17:39:17 +00:00
|
|
|
|
} from "@mui/material";
|
2023-11-15 18:38:02 +00:00
|
|
|
|
import { openCropModal } from "@root/cropModal";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import { closeImageUploadModal, openImageUploadModal } from "@root/imageUploadModal";
|
|
|
|
|
import { addQuestionVariant, setVariantImageUrl, setVariantOriginalImageUrl } from "@root/questions/actions";
|
2023-11-15 18:38:02 +00:00
|
|
|
|
import AddOrEditImageButton from "@ui_kit/AddOrEditImageButton";
|
|
|
|
|
import { CropModal } from "@ui_kit/Modal/CropModal";
|
2023-10-19 10:34:48 +00:00
|
|
|
|
import { useState } from "react";
|
2023-11-15 18:38:02 +00:00
|
|
|
|
import { EnterIcon } from "../../../assets/icons/questionsPage/enterIcon";
|
|
|
|
|
import type { QuizQuestionImages } from "../../../model/questionTypes/images";
|
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-03-30 18:39:59 +00:00
|
|
|
|
import SwitchAnswerOptionsPict from "./switchOptionsPict";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-10-03 14:03:57 +00:00
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
interface Props {
|
2023-11-15 18:38:02 +00:00
|
|
|
|
question: QuizQuestionImages;
|
2023-08-24 11:09:47 +00:00
|
|
|
|
}
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-11-15 18:38:02 +00:00
|
|
|
|
export default function OptionsPicture({ question }: Props) {
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const theme = useTheme();
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const [selectedVariantId, setSelectedVariantId] = useState<string | null>(null);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
const [switchState, setSwitchState] = useState("setting");
|
2023-11-16 16:41:25 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-11-15 18:38:02 +00:00
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
};
|
2023-03-30 18:39:59 +00:00
|
|
|
|
|
2023-10-23 15:48:27 +00:00
|
|
|
|
const handleImageUpload = (files: FileList | null) => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
if (!files?.length || !selectedVariantId) return;
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-23 15:48:27 +00:00
|
|
|
|
const [file] = Array.from(files);
|
|
|
|
|
const url = URL.createObjectURL(file);
|
2023-10-01 12:10:12 +00:00
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
setVariantImageUrl(question.id, selectedVariantId, url);
|
|
|
|
|
setVariantOriginalImageUrl(question.id, selectedVariantId, url);
|
|
|
|
|
closeImageUploadModal();
|
2023-10-23 15:48:27 +00:00
|
|
|
|
openCropModal(url, url);
|
2023-10-12 15:20:46 +00:00
|
|
|
|
};
|
2023-08-28 11:03:25 +00:00
|
|
|
|
|
2023-10-23 15:48:27 +00:00
|
|
|
|
function handleCropModalSaveClick(url: string) {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
if (!selectedVariantId) return;
|
|
|
|
|
|
|
|
|
|
setVariantImageUrl(question.id, selectedVariantId, url);
|
2023-10-23 15:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 15:20:46 +00:00
|
|
|
|
return (
|
2023-11-15 18:38:02 +00:00
|
|
|
|
<>
|
|
|
|
|
<Box sx={{ padding: "20px" }}>
|
|
|
|
|
<AnswerDraggableList
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question={question}
|
|
|
|
|
additionalContent={(variant) => (
|
2023-11-15 18:38:02 +00:00
|
|
|
|
<>
|
|
|
|
|
{!isMobile && (
|
|
|
|
|
<AddOrEditImageButton
|
|
|
|
|
imageSrc={variant.extendedText}
|
|
|
|
|
onImageClick={() => {
|
|
|
|
|
if (!("originalImageUrl" in variant)) return;
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
setSelectedVariantId(variant.id);
|
2023-11-15 18:38:02 +00:00
|
|
|
|
if (variant.extendedText) {
|
|
|
|
|
return openCropModal(
|
|
|
|
|
variant.extendedText,
|
2023-12-01 14:33:55 +00:00
|
|
|
|
variant.originalImageUrl || ""
|
2023-11-15 18:38:02 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
openImageUploadModal();
|
2023-11-15 18:38:02 +00:00
|
|
|
|
}}
|
|
|
|
|
onPlusClick={() => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
setSelectedVariantId(variant.id);
|
|
|
|
|
openImageUploadModal();
|
2023-11-15 18:38:02 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{ mx: "10px" }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
additionalMobile={(variant) => (
|
2023-11-15 18:38:02 +00:00
|
|
|
|
<>
|
|
|
|
|
{isMobile && (
|
|
|
|
|
<AddOrEditImageButton
|
|
|
|
|
imageSrc={variant.extendedText}
|
|
|
|
|
onImageClick={() => {
|
|
|
|
|
if (!("originalImageUrl" in variant)) return;
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
setSelectedVariantId(variant.id);
|
2023-11-15 18:38:02 +00:00
|
|
|
|
if (variant.extendedText) {
|
|
|
|
|
return openCropModal(
|
|
|
|
|
variant.extendedText,
|
2023-12-01 14:33:55 +00:00
|
|
|
|
variant.originalImageUrl || ""
|
2023-11-15 18:38:02 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
openImageUploadModal();
|
2023-11-15 18:38:02 +00:00
|
|
|
|
}}
|
|
|
|
|
onPlusClick={() => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
setSelectedVariantId(variant.id);
|
|
|
|
|
openImageUploadModal();
|
2023-11-15 18:38:02 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{ m: "8px", width: "auto" }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<UploadImageModal imgHC={handleImageUpload} />
|
2023-11-15 18:38:02 +00:00
|
|
|
|
<CropModal onSaveImageClick={handleCropModalSaveClick} />
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
|
|
|
|
<Link
|
|
|
|
|
component="button"
|
|
|
|
|
variant="body2"
|
|
|
|
|
sx={{ color: theme.palette.brightPurple.main }}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
onClick={() => addQuestionVariant(question.id)}
|
2023-11-15 18:38:02 +00:00
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</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",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<ButtonsOptions switchState={switchState} SSHC={SSHC} question={question} />
|
|
|
|
|
<SwitchAnswerOptionsPict switchState={switchState} question={question} />
|
2023-11-15 18:38:02 +00:00
|
|
|
|
</>
|
|
|
|
|
|
|
|
|
|
);
|
2023-08-24 11:09:47 +00:00
|
|
|
|
}
|