frontPanel/src/pages/Questions/PageOptions/PageOptions.tsx

137 lines
4.7 KiB
TypeScript
Raw Normal View History

2023-09-05 13:54:41 +00:00
import { useState } from "react";
2023-09-06 13:20:12 +00:00
import { useParams } from "react-router-dom";
2023-09-15 12:37:12 +00:00
import { Box, Typography, useMediaQuery, useTheme } from "@mui/material";
import ButtonsOptions from "../ButtonsOptions";
import CustomTextField from "@ui_kit/CustomTextField";
import AddImage from "../../../assets/icons/questionsPage/addImage";
import AddVideofile from "../../../assets/icons/questionsPage/addVideofile";
import SwitchPageOptions from "./switchPageOptions";
2023-09-05 13:54:41 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
import { UploadImageModal } from "../UploadImage/UploadImageModal";
import { UploadVideoModal } from "../UploadVideoModal";
2023-09-15 12:37:12 +00:00
import { AddPlusImage } from "@icons/questionsPage/addPlusImage";
import { AddPlusVideo } from "@icons/questionsPage/addPlusVideo";
2023-04-15 09:10:59 +00:00
type Props = {
disableInput?: boolean;
2023-08-12 08:31:21 +00:00
totalIndex: number;
2023-04-15 09:10:59 +00:00
};
export default function PageOptions({ disableInput, totalIndex }: Props) {
2023-09-05 13:54:41 +00:00
const [openImageModal, setOpenImageModal] = useState<boolean>(false);
const [openVideoModal, setOpenVideoModal] = useState<boolean>(false);
const [switchState, setSwitchState] = useState("setting");
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-09-05 13:54:41 +00:00
const { listQuestions } = questionStore();
2023-04-15 09:10:59 +00:00
const theme = useTheme();
2023-09-15 12:37:12 +00:00
const isTablet = useMediaQuery(theme.breakpoints.down(980));
const isMobile = useMediaQuery(theme.breakpoints.down(780));
2023-09-05 13:54:41 +00:00
2023-04-15 09:10:59 +00:00
const SSHC = (data: string) => {
setSwitchState(data);
};
2023-09-05 13:54:41 +00:00
2023-04-15 09:10:59 +00:00
return (
<>
<Box
sx={{
2023-09-15 12:37:12 +00:00
width: isTablet ? "auto" : "100%",
2023-04-15 09:10:59 +00:00
maxWidth: "640px",
display: "flex",
padding: "20px",
flexDirection: "column",
gap: "20px",
}}
>
<Box sx={{ display: disableInput ? "none" : "" }}>
2023-09-05 13:54:41 +00:00
<CustomTextField
placeholder={"Можно добавить текст"}
2023-09-06 13:20:12 +00:00
text={listQuestions[quizId][totalIndex].content.text}
2023-09-05 13:54:41 +00:00
onChange={({ target }) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-05 13:54:41 +00:00
clonContent.text = target.value;
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, { content: clonContent });
2023-09-05 13:54:41 +00:00
}}
/>
2023-04-15 09:10:59 +00:00
</Box>
2023-09-15 12:37:12 +00:00
<Box
sx={{ display: "flex", alignItems: "center", gap: "12px", justifyContent: isMobile ? "space-between" : null }}
>
2023-09-05 13:54:41 +00:00
<Box
onClick={() => setOpenImageModal(true)}
2023-04-15 09:10:59 +00:00
sx={{
2023-09-05 13:54:41 +00:00
cursor: "pointer",
display: "flex",
alignItems: "center",
gap: "10px",
2023-04-15 09:10:59 +00:00
}}
>
2023-09-15 12:37:12 +00:00
{isMobile ? <AddPlusImage /> : <AddImage />}
2023-09-05 13:54:41 +00:00
<Typography
sx={{
2023-09-15 12:37:12 +00:00
display: isMobile ? "none" : "block",
2023-09-05 13:54:41 +00:00
fontWeight: 400,
fontSize: "16px",
lineHeight: "18.96px",
color: theme.palette.grey2.main,
}}
>
Изображение
</Typography>
</Box>
<UploadImageModal
open={openImageModal}
onClose={() => setOpenImageModal(false)}
imgHC={(fileList) => {
if (fileList?.length) {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-05 13:54:41 +00:00
clonContent.picture = URL.createObjectURL(fileList[0]);
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
content: clonContent,
});
2023-09-05 13:54:41 +00:00
}
}}
/>
2023-04-15 09:10:59 +00:00
<Typography> или</Typography>
2023-09-05 13:54:41 +00:00
<Box
onClick={() => setOpenVideoModal(true)}
2023-04-15 09:10:59 +00:00
sx={{
2023-09-05 13:54:41 +00:00
cursor: "pointer",
display: "flex",
alignItems: "center",
gap: "10px",
2023-04-15 09:10:59 +00:00
}}
>
2023-09-15 12:37:12 +00:00
{isMobile ? <AddPlusVideo /> : <AddVideofile />}
2023-09-05 13:54:41 +00:00
<Typography
sx={{
2023-09-15 12:37:12 +00:00
display: isMobile ? "none" : "block",
2023-09-05 13:54:41 +00:00
fontWeight: 400,
fontSize: "16px",
lineHeight: "18.96px",
color: theme.palette.grey2.main,
}}
>
Видео
</Typography>
</Box>
<UploadVideoModal
open={openVideoModal}
onClose={() => setOpenVideoModal(false)}
2023-09-06 13:20:12 +00:00
video={listQuestions[quizId][totalIndex].content.video}
2023-09-05 13:54:41 +00:00
onUpload={(url) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-05 13:54:41 +00:00
clonContent.video = url;
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, { content: clonContent });
2023-09-05 13:54:41 +00:00
}}
/>
2023-04-15 09:10:59 +00:00
</Box>
</Box>
2023-09-15 12:37:12 +00:00
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
2023-08-24 11:09:47 +00:00
<SwitchPageOptions switchState={switchState} totalIndex={totalIndex} />
2023-04-15 09:10:59 +00:00
</>
);
}