2023-12-16 12:17:07 +00:00
|
|
|
|
import { useState, useEffect, useLayoutEffect, useRef } from "react";
|
|
|
|
|
import { Box, Button, IconButton, Typography, useMediaQuery, useTheme } 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-12-16 12:17:07 +00:00
|
|
|
|
import BranchingQuestions from "./BranchingModal/BranchingQuestionsModal";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
import { QuestionSwitchWindowTool } from "./QuestionSwitchWindowTool";
|
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { updateOpenBranchingPanel, updateEditSomeQuestion } from "@root/uiTools/actions";
|
|
|
|
|
import { useUiTools } from "@root/uiTools/store";
|
2023-12-01 14:33:55 +00:00
|
|
|
|
|
2023-12-27 07:25:30 +00:00
|
|
|
|
interface Props {
|
|
|
|
|
openBranchingPage: boolean;
|
|
|
|
|
setOpenBranchingPage: (a:boolean) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function QuestionsPage({
|
|
|
|
|
openBranchingPage,
|
|
|
|
|
setOpenBranchingPage}:Props) {
|
2023-12-16 12:17:07 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const { openedModalSettingsId, openBranchingPanel } = useUiTools();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
|
|
|
|
const quiz = useCurrentQuiz();
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
updateOpenBranchingPanel(false);
|
|
|
|
|
updateEditSomeQuestion();
|
|
|
|
|
}, []);
|
2023-06-27 22:26:23 +00:00
|
|
|
|
|
2023-12-16 12:17:07 +00:00
|
|
|
|
const ref = useRef();
|
|
|
|
|
if (!quiz) return null;
|
2023-09-15 12:37:12 +00:00
|
|
|
|
|
2023-12-16 12:17:07 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
ref={ref}
|
|
|
|
|
id="QuestionsPage"
|
|
|
|
|
sx={{
|
|
|
|
|
maxWidth: "796px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
margin: "60px 0 40px 0",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant={"h5"}>{quiz.name ? quiz.name : "Заголовок квиза"}</Typography>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{
|
|
|
|
|
display: openBranchingPanel ? "none" : "flex",
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
lineHeight: "19px",
|
|
|
|
|
padding: 0,
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
textDecorationColor: theme.palette.brightPurple.main,
|
|
|
|
|
}}
|
|
|
|
|
onClick={collapseAllQuestions}
|
|
|
|
|
>
|
|
|
|
|
Свернуть всё
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
2023-12-27 07:25:30 +00:00
|
|
|
|
<QuestionSwitchWindowTool
|
|
|
|
|
openBranchingPage={openBranchingPage}
|
|
|
|
|
setOpenBranchingPage={setOpenBranchingPage}
|
|
|
|
|
/>
|
2023-12-16 12:17:07 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
maxWidth: "796px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
createUntypedQuestion(quiz.backendId);
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
position: "fixed",
|
|
|
|
|
left: isMobile ? "20px" : "250px",
|
2023-12-17 22:34:22 +00:00
|
|
|
|
bottom: "140px",
|
2023-12-16 12:17:07 +00:00
|
|
|
|
}}
|
|
|
|
|
data-cy="create-question"
|
|
|
|
|
>
|
|
|
|
|
<AddPlus />
|
|
|
|
|
</IconButton>
|
2023-12-04 09:30:14 +00:00
|
|
|
|
|
2023-12-16 12:17:07 +00:00
|
|
|
|
<Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
sx={{ padding: "10px 20px", borderRadius: "8px", height: "44px" }}
|
|
|
|
|
data-cy="back-button"
|
|
|
|
|
onClick={decrementCurrentStep}
|
|
|
|
|
>
|
|
|
|
|
<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)}
|
|
|
|
|
{openedModalSettingsId !== null && <BranchingQuestions />}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-12-10 01:01:56 +00:00
|
|
|
|
}
|