frontPanel/src/pages/Questions/QuestionsPage.tsx

117 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-09-20 09:07:33 +00:00
import {
2023-10-03 16:05:20 +00:00
Box,
Button,
IconButton,
Typography,
useMediaQuery,
useTheme,
2023-09-20 09:07:33 +00:00
} from "@mui/material";
import AddPlus from "../../assets/icons/questionsPage/addPlus";
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
2023-08-03 07:45:06 +00:00
import { quizStore } from "@root/quizes";
import { useParams } from "react-router-dom";
2023-09-20 09:07:33 +00:00
import {
2023-10-03 16:05:20 +00:00
questionStore,
createQuestion,
updateQuestionsList,
2023-09-20 09:07:33 +00:00
} from "@root/questions";
2023-08-11 07:25:28 +00:00
import { DraggableList } from "./DraggableList";
2023-10-04 09:07:59 +00:00
import type { AnyQuizQuestion } from "../../model/questionTypes/shared";
2023-10-03 16:05:20 +00:00
import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
2023-10-05 11:41:54 +00:00
import { createPortal } from "react-dom";
export default function QuestionsPage() {
2023-10-03 16:05:20 +00:00
const { listQuizes, updateQuizesList } = quizStore();
const quizId = Number(useParams().quizId);
const { listQuestions } = questionStore();
const handleNext = () => {
updateQuizesList(quizId, { step: listQuizes[quizId].step + 1 });
};
2023-10-03 16:05:20 +00:00
const handleBack = () => {
let result = listQuizes[quizId].step - 1;
updateQuizesList(quizId, { step: result ? result : 1 });
};
2023-09-05 08:25:47 +00:00
const collapseEverything = () => {
2023-09-06 11:51:08 +00:00
listQuestions[quizId].forEach((item, index) => {
2023-10-04 09:07:59 +00:00
updateQuestionsList<AnyQuizQuestion>(quizId, index, {
...item,
expanded: false,
});
2023-09-05 08:25:47 +00:00
});
};
2023-10-03 16:05:20 +00:00
const theme = useTheme();
const isTablet = useMediaQuery(theme.breakpoints.up(1000));
2023-09-15 12:37:12 +00:00
2023-04-15 09:10:59 +00:00
return (
<>
2023-09-15 12:37:12 +00:00
{/* <Stepper activeStep={activeStep} desc={"Задайте вопросы"} /> */}
2023-08-03 07:45:06 +00:00
<Box
sx={{
maxWidth: "796px",
width: "100%",
display: "flex",
justifyContent: "space-between",
margin: "60px 0 40px 0",
}}
>
<Typography variant={"h5"}>Заголовок квиза</Typography>
2023-09-05 08:25:47 +00:00
<Button
2023-08-03 07:45:06 +00:00
sx={{
fontSize: "16px",
lineHeight: "19px",
2023-09-05 08:25:47 +00:00
padding: 0,
textDecoration: "underline",
2023-08-03 07:45:06 +00:00
color: theme.palette.brightPurple.main,
textDecorationColor: theme.palette.brightPurple.main,
}}
2023-09-05 08:25:47 +00:00
onClick={collapseEverything}
>
2023-08-03 07:45:06 +00:00
Свернуть всё
2023-09-05 08:25:47 +00:00
</Button>
2023-08-03 07:45:06 +00:00
</Box>
2023-08-11 07:25:28 +00:00
<DraggableList />
2023-08-03 07:45:06 +00:00
<Box
sx={{
display: "flex",
justifyContent: "space-between",
maxWidth: "796px",
}}
>
<IconButton
2023-08-03 07:45:06 +00:00
onClick={() => {
2023-09-06 11:51:08 +00:00
createQuestion(quizId);
2023-08-03 07:45:06 +00:00
}}
>
2023-04-15 09:10:59 +00:00
<AddPlus />
</IconButton>
<Box sx={{ display: "flex", gap: "8px" }}>
2023-09-20 09:07:33 +00:00
<Button
variant="outlined"
sx={{ padding: "10px 20px", borderRadius: "8px", height: "44px" }}
>
2023-04-15 09:10:59 +00:00
<ArrowLeft />
</Button>
<Button
variant="contained"
sx={{
2023-09-15 12:37:12 +00:00
height: "44px",
2023-04-15 09:10:59 +00:00
padding: "10px 20px",
borderRadius: "8px",
background: theme.palette.brightPurple.main,
fontSize: "18px",
}}
onClick={handleNext}
2023-04-15 09:10:59 +00:00
>
Следующий шаг
</Button>
</Box>
</Box>
2023-10-09 12:54:39 +00:00
{createPortal(<QuizPreview />, document.body)}
2023-04-15 09:10:59 +00:00
</>
);
}