2023-10-18 11:07:08 +00:00
|
|
|
|
import { VideofileIcon } from "@icons/questionsPage/VideofileIcon";
|
2023-09-15 12:37:12 +00:00
|
|
|
|
import { Box, Typography, useMediaQuery, useTheme } from "@mui/material";
|
2023-12-01 18:05:59 +00:00
|
|
|
|
import { updateQuestion, uploadQuestionImage } from "@root/questions/actions";
|
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import AddOrEditImageButton from "@ui_kit/AddOrEditImageButton";
|
2023-10-18 11:07:08 +00:00
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
2023-12-04 11:57:54 +00:00
|
|
|
|
import { CropModal, useCropModalState } from "@ui_kit/Modal/CropModal";
|
2023-10-24 13:02:09 +00:00
|
|
|
|
import { useState } from "react";
|
2023-09-20 09:07:33 +00:00
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
2023-11-16 16:41:25 +00:00
|
|
|
|
import type { QuizQuestionPage } from "../../../model/questionTypes/page";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
import ButtonsOptions from "../ButtonsOptions";
|
2023-09-05 13:54:41 +00:00
|
|
|
|
import { UploadImageModal } from "../UploadImage/UploadImageModal";
|
|
|
|
|
|
import { UploadVideoModal } from "../UploadVideoModal";
|
2023-10-18 11:07:08 +00:00
|
|
|
|
import SwitchPageOptions from "./switchPageOptions";
|
2023-12-02 09:35:35 +00:00
|
|
|
|
import { useDisclosure } from "../../../utils/useDisclosure";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
|
2023-10-03 14:03:57 +00:00
|
|
|
|
|
2023-04-15 09:10:59 +00:00
|
|
|
|
type Props = {
|
2023-10-18 11:07:08 +00:00
|
|
|
|
disableInput?: boolean;
|
2023-11-16 16:41:25 +00:00
|
|
|
|
question: QuizQuestionPage;
|
2023-04-15 09:10:59 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
export default function PageOptions({ disableInput, question }: Props) {
|
2023-10-18 11:07:08 +00:00
|
|
|
|
const [openVideoModal, setOpenVideoModal] = useState<boolean>(false);
|
|
|
|
|
|
const [switchState, setSwitchState] = useState("setting");
|
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(980));
|
|
|
|
|
|
const isFigmaTablet = useMediaQuery(theme.breakpoints.down(990));
|
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(780));
|
2023-12-01 18:05:59 +00:00
|
|
|
|
const quizQid = useCurrentQuiz()?.qid;
|
2023-12-04 11:57:54 +00:00
|
|
|
|
const {
|
|
|
|
|
|
isCropModalOpen,
|
|
|
|
|
|
openCropModal,
|
|
|
|
|
|
closeCropModal,
|
|
|
|
|
|
imageBlob,
|
|
|
|
|
|
originalImageUrl,
|
|
|
|
|
|
setCropModalImageBlob,
|
|
|
|
|
|
} = useCropModalState();
|
2023-12-02 09:35:35 +00:00
|
|
|
|
const [isImageUploadOpen, openImageUploadModal, closeImageUploadModal] = useDisclosure();
|
2023-11-16 16:41:25 +00:00
|
|
|
|
|
|
|
|
|
|
const setText = useDebouncedCallback((value) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
if (question.type !== "page") return;
|
|
|
|
|
|
|
|
|
|
|
|
question.content.text = value;
|
2023-10-18 11:07:08 +00:00
|
|
|
|
});
|
2023-11-27 23:07:24 +00:00
|
|
|
|
}, 200);
|
2023-09-05 13:54:41 +00:00
|
|
|
|
|
2023-10-18 11:07:08 +00:00
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
|
};
|
2023-10-03 20:11:58 +00:00
|
|
|
|
|
2023-12-04 11:57:54 +00:00
|
|
|
|
async function handleImageUpload(file: File) {
|
|
|
|
|
|
const url = await uploadQuestionImage(question.id, quizQid, file, (question, url) => {
|
2023-12-01 18:05:59 +00:00
|
|
|
|
if (question.type !== "page") return;
|
2023-10-24 13:02:09 +00:00
|
|
|
|
|
2023-12-01 18:05:59 +00:00
|
|
|
|
question.content.picture = url;
|
|
|
|
|
|
question.content.originalPicture = url;
|
|
|
|
|
|
});
|
2023-11-16 16:41:25 +00:00
|
|
|
|
closeImageUploadModal();
|
2023-12-04 11:57:54 +00:00
|
|
|
|
openCropModal(file, url);
|
2023-10-24 13:02:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-01 18:05:59 +00:00
|
|
|
|
function handleCropModalSaveClick(imageBlob: Blob) {
|
|
|
|
|
|
uploadQuestionImage(question.id, quizQid, imageBlob, (question, url) => {
|
|
|
|
|
|
if (question.type !== "page") return;
|
|
|
|
|
|
|
|
|
|
|
|
question.content.picture = url;
|
|
|
|
|
|
});
|
2023-10-24 13:02:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-18 11:07:08 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Box
|
2023-10-03 20:11:58 +00:00
|
|
|
|
sx={{
|
2023-10-18 11:07:08 +00:00
|
|
|
|
width: isTablet ? "auto" : "100%",
|
|
|
|
|
|
maxWidth: isFigmaTablet ? "549px" : "640px",
|
2023-10-03 20:11:58 +00:00
|
|
|
|
display: "flex",
|
2023-10-18 11:07:08 +00:00
|
|
|
|
px: "20px",
|
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
|
gap: isMobile ? "25px" : "20px",
|
2023-09-26 21:11:27 +00:00
|
|
|
|
}}
|
2023-10-18 11:07:08 +00:00
|
|
|
|
>
|
|
|
|
|
|
<Box sx={{ display: disableInput ? "none" : "", mt: isMobile ? "15px" : "0px" }}>
|
|
|
|
|
|
<CustomTextField
|
|
|
|
|
|
placeholder={"Можно добавить текст"}
|
|
|
|
|
|
text={question.content.text}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
onChange={({ target }) => setText(target.value)}
|
2023-10-18 11:07:08 +00:00
|
|
|
|
/>
|
2023-09-26 21:11:27 +00:00
|
|
|
|
</Box>
|
2023-09-15 12:37:12 +00:00
|
|
|
|
|
2023-10-03 20:11:58 +00:00
|
|
|
|
<Box
|
2023-10-18 11:07:08 +00:00
|
|
|
|
sx={{
|
|
|
|
|
|
mb: "20px",
|
|
|
|
|
|
ml: isTablet ? "0px" : "60px",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
gap: "28px",
|
|
|
|
|
|
justifyContent: isMobile ? "space-between" : null,
|
2023-10-03 20:11:58 +00:00
|
|
|
|
}}
|
2023-09-26 21:11:27 +00:00
|
|
|
|
>
|
2023-10-18 11:07:08 +00:00
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
gap: "20px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2023-10-24 13:02:09 +00:00
|
|
|
|
<AddOrEditImageButton
|
|
|
|
|
|
imageSrc={question.content.picture}
|
|
|
|
|
|
onImageClick={() => {
|
|
|
|
|
|
if (question.content.picture) {
|
2023-12-04 11:57:54 +00:00
|
|
|
|
return openCropModal(
|
2023-10-24 13:02:09 +00:00
|
|
|
|
question.content.picture,
|
|
|
|
|
|
question.content.originalPicture
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-16 16:41:25 +00:00
|
|
|
|
openImageUploadModal();
|
2023-10-24 13:02:09 +00:00
|
|
|
|
}}
|
|
|
|
|
|
onPlusClick={() => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
openImageUploadModal();
|
2023-10-24 13:02:09 +00:00
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2023-09-15 12:37:12 +00:00
|
|
|
|
|
2023-10-18 11:07:08 +00:00
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: isMobile ? "none" : "block",
|
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
|
lineHeight: "18.96px",
|
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Изображение
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
</Box>
|
2023-12-04 11:57:54 +00:00
|
|
|
|
<UploadImageModal
|
|
|
|
|
|
isOpen={isImageUploadOpen}
|
|
|
|
|
|
onClose={closeImageUploadModal}
|
|
|
|
|
|
handleImageChange={handleImageUpload}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<CropModal
|
|
|
|
|
|
isOpen={isCropModalOpen}
|
|
|
|
|
|
imageBlob={imageBlob}
|
|
|
|
|
|
originalImageUrl={originalImageUrl}
|
|
|
|
|
|
setCropModalImageBlob={setCropModalImageBlob}
|
|
|
|
|
|
onClose={closeCropModal}
|
|
|
|
|
|
onSaveImageClick={handleCropModalSaveClick}
|
|
|
|
|
|
/>
|
2023-10-18 11:07:08 +00:00
|
|
|
|
<Typography> или</Typography>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
gap: "10px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{isMobile ? (
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
width: "120px",
|
|
|
|
|
|
position: "relative",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
background: "#EEE4FC",
|
|
|
|
|
|
height: "40px",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
|
borderTopLeftRadius: "4px",
|
|
|
|
|
|
borderBottomLeftRadius: "4px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<VideofileIcon
|
|
|
|
|
|
style={{
|
|
|
|
|
|
color: "#7E2AEA",
|
|
|
|
|
|
fontSize: "20px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
width: "20px",
|
|
|
|
|
|
background: "#EEE4FC",
|
|
|
|
|
|
height: "40px",
|
|
|
|
|
|
color: "white",
|
|
|
|
|
|
backgroundColor: "#7E2AEA",
|
|
|
|
|
|
borderTopRightRadius: "4px",
|
|
|
|
|
|
borderBottomRightRadius: "4px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
+
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "60px",
|
|
|
|
|
|
height: "40px",
|
|
|
|
|
|
background: "#EEE4FC",
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "center", width: "100%" }}>
|
|
|
|
|
|
<VideofileIcon fontSize="22px" color="#7E2AEA" />
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<span
|
|
|
|
|
|
style={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
|
background: "#7E2AEA",
|
|
|
|
|
|
height: "100%",
|
|
|
|
|
|
width: "25px",
|
|
|
|
|
|
color: "white",
|
|
|
|
|
|
fontSize: "15px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
+
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: isMobile ? "none" : "block",
|
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
|
lineHeight: "18.96px",
|
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Видео
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<UploadVideoModal
|
|
|
|
|
|
open={openVideoModal}
|
|
|
|
|
|
onClose={() => setOpenVideoModal(false)}
|
|
|
|
|
|
video={question.content.video}
|
|
|
|
|
|
onUpload={(url) => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
updateQuestion(question.id, question => {
|
2023-11-16 16:41:25 +00:00
|
|
|
|
if (question.type !== "page") return;
|
|
|
|
|
|
|
|
|
|
|
|
question.content.video = url;
|
2023-10-18 11:07:08 +00:00
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
2023-11-16 16:41:25 +00:00
|
|
|
|
<ButtonsOptions switchState={switchState} SSHC={SSHC} question={question} />
|
|
|
|
|
|
<SwitchPageOptions switchState={switchState} question={question} />
|
2023-10-18 11:07:08 +00:00
|
|
|
|
</>
|
|
|
|
|
|
);
|
2023-04-15 09:10:59 +00:00
|
|
|
|
}
|