2023-12-05 15:49:42 +00:00
|
|
|
|
import { useState, useEffect, useLayoutEffect, useRef } from "react"
|
2023-09-20 09:07:33 +00:00
|
|
|
|
import {
|
2023-11-14 20:15:52 +00:00
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
IconButton,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2023-09-20 09:07:33 +00:00
|
|
|
|
} from "@mui/material";
|
2023-11-29 13:49:52 +00:00
|
|
|
|
import { collapseAllQuestions, createUntypedQuestion } from "@root/questions/actions";
|
2023-11-27 23:07:24 +00:00
|
|
|
|
import { decrementCurrentStep, incrementCurrentStep } from "@root/quizes/actions";
|
2023-11-14 20:15:52 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
|
|
|
|
import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
|
|
|
|
|
import { createPortal } from "react-dom";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import AddPlus from "../../assets/icons/questionsPage/addPlus";
|
|
|
|
|
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
import BranchingQuestions from "./BranchingModal/BranchingQuestionsModal"
|
|
|
|
|
import { QuestionSwitchWindowTool } from "./QuestionSwitchWindowTool";
|
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-05 23:34:40 +00:00
|
|
|
|
import { updateOpenBranchingPanel, updateEditSomeQuestion } from "@root/questions/actions";
|
2023-12-01 14:33:55 +00:00
|
|
|
|
|
|
|
|
|
|
2023-03-15 22:56:53 +00:00
|
|
|
|
export default function QuestionsPage() {
|
2023-11-14 20:15:52 +00:00
|
|
|
|
const theme = useTheme();
|
2023-11-29 15:45:15 +00:00
|
|
|
|
const { openedModalSettingsId } = useQuestionsStore();
|
2023-11-14 20:15:52 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
2023-11-27 23:07:24 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-04 16:33:45 +00:00
|
|
|
|
const {openBranchingPanel} = useQuestionsStore.getState()
|
2023-12-04 20:41:44 +00:00
|
|
|
|
useLayoutEffect(() => {
|
2023-12-05 23:34:40 +00:00
|
|
|
|
updateOpenBranchingPanel(false)
|
|
|
|
|
updateEditSomeQuestion()
|
2023-12-04 20:41:44 +00:00
|
|
|
|
},[])
|
2023-06-27 22:26:23 +00:00
|
|
|
|
|
2023-12-05 15:49:42 +00:00
|
|
|
|
const ref = useRef()
|
2023-11-14 20:15:52 +00:00
|
|
|
|
if (!quiz) return null;
|
2023-09-15 12:37:12 +00:00
|
|
|
|
|
2023-12-04 09:30:14 +00:00
|
|
|
|
|
2023-11-14 20:15:52 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box
|
2023-12-05 15:49:42 +00:00
|
|
|
|
ref={ref}
|
2023-12-05 23:34:40 +00:00
|
|
|
|
id="QuestionsPage"
|
2023-11-14 20:15:52 +00:00
|
|
|
|
sx={{
|
|
|
|
|
maxWidth: "796px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
margin: "60px 0 40px 0",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant={"h5"}>Заголовок квиза</Typography>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{
|
2023-12-04 11:44:08 +00:00
|
|
|
|
display: openBranchingPanel ? "none" : "flex",
|
2023-11-14 20:15:52 +00:00
|
|
|
|
fontSize: "16px",
|
|
|
|
|
lineHeight: "19px",
|
|
|
|
|
padding: 0,
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
textDecorationColor: theme.palette.brightPurple.main,
|
|
|
|
|
}}
|
2023-11-16 16:41:25 +00:00
|
|
|
|
onClick={collapseAllQuestions}
|
2023-11-14 20:15:52 +00:00
|
|
|
|
>
|
|
|
|
|
Свернуть всё
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
2023-12-04 11:44:08 +00:00
|
|
|
|
<QuestionSwitchWindowTool/>
|
2023-11-14 20:15:52 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
maxWidth: "796px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
2023-11-29 13:49:52 +00:00
|
|
|
|
createUntypedQuestion(quiz.backendId);
|
2023-11-14 20:15:52 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
position: "fixed",
|
|
|
|
|
left: isMobile ? "20px" : "250px",
|
|
|
|
|
bottom: "20px",
|
|
|
|
|
}}
|
2023-11-27 23:07:24 +00:00
|
|
|
|
data-cy="create-question"
|
2023-11-14 20:15:52 +00:00
|
|
|
|
>
|
|
|
|
|
<AddPlus />
|
|
|
|
|
</IconButton>
|
2023-12-05 15:49:42 +00:00
|
|
|
|
|
2023-12-05 23:34:40 +00:00
|
|
|
|
|
2023-11-14 20:15:52 +00:00
|
|
|
|
<Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
sx={{ padding: "10px 20px", borderRadius: "8px", height: "44px" }}
|
2023-11-27 23:07:24 +00:00
|
|
|
|
data-cy="back-button"
|
|
|
|
|
onClick={decrementCurrentStep}
|
2023-11-14 20:15:52 +00:00
|
|
|
|
>
|
|
|
|
|
<ArrowLeft />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{
|
|
|
|
|
height: "44px",
|
|
|
|
|
padding: "10px 20px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
background: theme.palette.brightPurple.main,
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
}}
|
|
|
|
|
onClick={incrementCurrentStep}
|
|
|
|
|
>
|
|
|
|
|
Следующий шаг
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
{createPortal(<QuizPreview />, document.body)}
|
2023-12-03 02:16:53 +00:00
|
|
|
|
{openedModalSettingsId !== null && <BranchingQuestions/>}
|
2023-11-14 20:15:52 +00:00
|
|
|
|
</>
|
|
|
|
|
);
|
2023-12-05 15:49:42 +00:00
|
|
|
|
}
|