frontPanel/src/pages/Questions/QuestionsPage.tsx

124 lines
3.6 KiB
TypeScript
Raw Normal View History

import { Box, Button, IconButton, Typography, useTheme } from "@mui/material";
2023-12-31 02:53:25 +00:00
import {
collapseAllQuestions,
createUntypedQuestion,
} from "@root/questions/actions";
import {
decrementCurrentStep,
incrementCurrentStep,
} from "@root/quizes/actions";
2023-11-14 20:15:52 +00:00
import { useCurrentQuiz } from "@root/quizes/hooks";
import { updateEditSomeQuestion } from "@root/uiTools/actions";
import { useUiTools } from "@root/uiTools/store";
2023-11-14 20:15:52 +00:00
import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
import { useLayoutEffect, useRef } from "react";
2023-11-14 20:15:52 +00:00
import { createPortal } from "react-dom";
import AddPlus from "../../assets/icons/questionsPage/addPlus";
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
import BranchingQuestions from "./BranchingModal/BranchingQuestionsModal";
2023-11-29 15:45:15 +00:00
import { QuestionSwitchWindowTool } from "./QuestionSwitchWindowTool";
2023-12-01 14:33:55 +00:00
interface Props {
openBranchingPage: boolean;
setOpenBranchingPage: (a: boolean) => void;
widthMain: number;
}
2023-12-31 02:53:25 +00:00
export default function QuestionsPage({
openBranchingPage,
setOpenBranchingPage,
widthMain,
2023-12-31 02:53:25 +00:00
}: Props) {
const theme = useTheme();
const { openedModalSettingsId } = useUiTools();
const quiz = useCurrentQuiz();
useLayoutEffect(() => {
updateEditSomeQuestion();
}, []);
if (!quiz) return null;
2023-09-15 12:37:12 +00:00
return (
<>
<Box
id="QuestionsPage"
sx={{
maxWidth: "796px",
width: "100%",
display: "flex",
justifyContent: "space-between",
margin: "60px 0 40px 0",
}}
>
<Typography variant={"h5"} sx={{ wordBreak: "break-word" }}>
2023-12-31 02:53:25 +00:00
{quiz.name ? quiz.name : "Заголовок quiz"}
</Typography>
{!openBranchingPage && (
<Button
sx={{
fontSize: "16px",
lineHeight: "19px",
padding: 0,
textDecoration: "underline",
color: theme.palette.brightPurple.main,
textDecorationColor: theme.palette.brightPurple.main,
}}
onClick={collapseAllQuestions}
>
Свернуть всё
</Button>
)}
</Box>
2023-12-31 02:53:25 +00:00
<QuestionSwitchWindowTool
openBranchingPage={openBranchingPage}
setOpenBranchingPage={setOpenBranchingPage}
widthMain={widthMain}
2023-12-31 02:53:25 +00:00
/>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
maxWidth: "796px",
position: "relative",
}}
>
{!openBranchingPage && (
<IconButton
2024-03-19 13:52:33 +00:00
onClick={() => createUntypedQuestion(quiz.backendId)}
sx={{ position: "fixed", bottom: "103px" }}
data-cy="create-question"
>
<AddPlus />
</IconButton>
)}
<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
2024-01-18 15:18:32 +00:00
data-cy="next-step"
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
}