frontPanel/src/pages/Questions/QuestionsPage.tsx

130 lines
4.7 KiB
TypeScript
Raw Normal View History

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";
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";
import { updateOpenBranchingPanel } from "@root/questions/actions";
2023-12-01 14:33:55 +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();
const {openBranchingPanel} = useQuestionsStore.getState()
useLayoutEffect(() => {
updateOpenBranchingPanel(true)
},[])
const ref = useRef()
2023-11-14 20:15:52 +00:00
if (!quiz) return null;
2023-09-15 12:37:12 +00:00
2023-11-14 20:15:52 +00:00
return (
<>
<Box
ref={ref}
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={{
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,
}}
onClick={collapseAllQuestions}
2023-11-14 20:15:52 +00:00
>
Свернуть всё
</Button>
</Box>
<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>
<Button
onClick={() => {
ref.current?.scrollIntoView({
behavior: 'smooth'
}
)}}
sx={{
display: isMobile ? "none" : "block",
position: "fixed",
right: isMobile ? "60px" : "400px",
bottom: "75px",
}}
>
вверх
</Button>
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)}
{openedModalSettingsId !== null && <BranchingQuestions/>}
2023-11-14 20:15:52 +00:00
</>
);
}