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

209 lines
7.1 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";
2023-09-20 09:07:33 +00:00
import { useDebouncedCallback } from "use-debounce";
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-09-26 21:11:27 +00:00
import { ImageAddIcons } from "@icons/ImageAddIcons";
import { VideofileIcon } from "@icons/questionsPage/VideofileIcon";
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));
2023-09-28 21:17:01 +00:00
const isFigmaTablet = useMediaQuery(theme.breakpoints.down(990));
2023-09-15 12:37:12 +00:00
const isMobile = useMediaQuery(theme.breakpoints.down(780));
2023-09-20 09:07:33 +00:00
const debounced = useDebouncedCallback((value) => {
const clonContent = listQuestions[quizId][totalIndex].content;
clonContent.text = value;
updateQuestionsList(quizId, totalIndex, { content: clonContent });
}, 1000);
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-09-28 21:17:01 +00:00
maxWidth: isFigmaTablet ? "549px" : "640px",
2023-04-15 09:10:59 +00:00
display: "flex",
2023-09-26 21:11:27 +00:00
px: "20px",
2023-04-15 09:10:59 +00:00
flexDirection: "column",
2023-09-26 21:11:27 +00:00
gap: isMobile ? "25px" : "20px",
2023-04-15 09:10:59 +00:00
}}
>
<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-20 09:07:33 +00:00
onChange={({ target }) => debounced(target.value)}
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
2023-09-20 09:07:33 +00:00
sx={{
2023-09-26 21:11:27 +00:00
mb: "20px",
ml: isTablet ? "0px" : "60px",
2023-09-20 09:07:33 +00:00
display: "flex",
alignItems: "center",
2023-09-28 21:17:01 +00:00
gap: "28px",
2023-09-20 09:07:33 +00:00
justifyContent: isMobile ? "space-between" : null,
}}
2023-09-15 12:37:12 +00:00
>
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",
2023-09-28 21:17:01 +00:00
gap: "20px",
2023-04-15 09:10:59 +00:00
}}
>
2023-09-26 21:11:27 +00:00
{isMobile ? (
<AddPlusImage />
) : (
<Box
sx={{
width: "60px",
height: "40px",
background: "#EEE4FC",
display: "flex",
justifyContent: "space-between",
}}
>
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "center", width: "100%" }}>
<ImageAddIcons 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>
)}
2023-09-15 12:37:12 +00:00
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-09-26 21:11:27 +00:00
// onClick={() => setOpenVideoModal(true)}
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
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-26 21:11:27 +00:00
{isMobile ? (
<AddPlusVideo />
) : (
<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>
)}
2023-09-15 12:37:12 +00:00
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-26 21:11:27 +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
</>
);
}