2023-10-09 12:33:45 +00:00
|
|
|
|
import { Box, Button, LinearProgress, Paper, Typography } from "@mui/material";
|
2023-10-09 16:04:12 +00:00
|
|
|
|
import { questionStore } from "@root/questions";
|
2023-10-17 13:24:37 +00:00
|
|
|
|
import {
|
|
|
|
|
decrementCurrentQuestionIndex,
|
|
|
|
|
incrementCurrentQuestionIndex,
|
|
|
|
|
useQuizPreviewStore,
|
|
|
|
|
} from "@root/quizPreview";
|
2023-10-15 17:37:52 +00:00
|
|
|
|
import { DefiniteQuestionType } from "model/questionTypes/shared";
|
2023-10-09 16:04:12 +00:00
|
|
|
|
import { FC, useEffect } from "react";
|
2023-10-09 12:33:45 +00:00
|
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
|
|
|
|
|
import Date from "./QuizPreviewQuestionTypes/Date";
|
2023-10-09 16:04:12 +00:00
|
|
|
|
import Emoji from "./QuizPreviewQuestionTypes/Emoji";
|
2023-10-09 12:33:45 +00:00
|
|
|
|
import File from "./QuizPreviewQuestionTypes/File";
|
2023-10-09 16:04:12 +00:00
|
|
|
|
import Images from "./QuizPreviewQuestionTypes/Images";
|
|
|
|
|
import Number from "./QuizPreviewQuestionTypes/Number";
|
2023-10-09 12:33:45 +00:00
|
|
|
|
import Page from "./QuizPreviewQuestionTypes/Page";
|
|
|
|
|
import Rating from "./QuizPreviewQuestionTypes/Rating";
|
2023-10-09 16:04:12 +00:00
|
|
|
|
import Select from "./QuizPreviewQuestionTypes/Select";
|
|
|
|
|
import Text from "./QuizPreviewQuestionTypes/Text";
|
|
|
|
|
import Variant from "./QuizPreviewQuestionTypes/Variant";
|
|
|
|
|
import Varimg from "./QuizPreviewQuestionTypes/Varimg";
|
2023-10-09 12:33:45 +00:00
|
|
|
|
|
2023-10-13 12:09:05 +00:00
|
|
|
|
const QuestionPreviewComponentByType: Record<DefiniteQuestionType, FC<any>> = {
|
2023-10-17 13:24:37 +00:00
|
|
|
|
variant: Variant,
|
|
|
|
|
images: Images,
|
|
|
|
|
varimg: Varimg,
|
|
|
|
|
emoji: Emoji,
|
|
|
|
|
text: Text,
|
|
|
|
|
select: Select,
|
|
|
|
|
date: Date,
|
|
|
|
|
number: Number,
|
|
|
|
|
file: File,
|
|
|
|
|
page: Page,
|
|
|
|
|
rating: Rating,
|
2023-10-09 12:33:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function QuizPreviewLayout() {
|
2023-10-17 13:24:37 +00:00
|
|
|
|
const quizId = useParams().quizId ?? 0;
|
|
|
|
|
const listQuestions = questionStore((state) => state.listQuestions);
|
|
|
|
|
const currentQuizStep = useQuizPreviewStore(
|
|
|
|
|
(state) => state.currentQuestionIndex
|
|
|
|
|
);
|
2023-10-09 12:33:45 +00:00
|
|
|
|
|
2023-10-17 13:24:37 +00:00
|
|
|
|
const quizQuestions = listQuestions[quizId] ?? [];
|
|
|
|
|
const nonDeletedQuizQuestions = quizQuestions.filter(
|
|
|
|
|
(question) => !question.deleted
|
|
|
|
|
);
|
|
|
|
|
const maxCurrentQuizStep =
|
|
|
|
|
nonDeletedQuizQuestions.length > 0 ? nonDeletedQuizQuestions.length - 1 : 0;
|
|
|
|
|
const currentProgress = Math.floor(
|
|
|
|
|
(currentQuizStep / maxCurrentQuizStep) * 100
|
|
|
|
|
);
|
2023-10-09 16:04:12 +00:00
|
|
|
|
|
2023-10-17 13:24:37 +00:00
|
|
|
|
const currentQuestion = nonDeletedQuizQuestions[currentQuizStep];
|
|
|
|
|
const QuestionComponent = currentQuestion
|
|
|
|
|
? QuestionPreviewComponentByType[
|
|
|
|
|
currentQuestion.type as DefiniteQuestionType
|
|
|
|
|
]
|
|
|
|
|
: null;
|
2023-10-09 12:33:45 +00:00
|
|
|
|
|
2023-10-17 13:24:37 +00:00
|
|
|
|
const questionElement = QuestionComponent ? (
|
|
|
|
|
<QuestionComponent key={currentQuestion.id} question={currentQuestion} />
|
|
|
|
|
) : null;
|
2023-10-09 12:33:45 +00:00
|
|
|
|
|
2023-10-17 13:24:37 +00:00
|
|
|
|
useEffect(
|
|
|
|
|
function resetCurrentQuizStep() {
|
|
|
|
|
if (currentQuizStep > maxCurrentQuizStep) {
|
|
|
|
|
decrementCurrentQuestionIndex();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[currentQuizStep, maxCurrentQuizStep]
|
|
|
|
|
);
|
2023-10-09 12:33:45 +00:00
|
|
|
|
|
2023-10-17 13:24:37 +00:00
|
|
|
|
return (
|
|
|
|
|
<Paper
|
|
|
|
|
className="quiz-preview-draghandle"
|
|
|
|
|
sx={{
|
|
|
|
|
height: "100%",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
pointerEvents: "auto",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
p: "16px",
|
|
|
|
|
whiteSpace: "break-spaces",
|
|
|
|
|
overflowY: "auto",
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
"&::-webkit-scrollbar": { width: 0 },
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{questionElement}
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
mt: "auto",
|
|
|
|
|
p: "16px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
borderTop: "1px solid #E3E3E3",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
flexGrow: 1,
|
2023-10-09 12:33:45 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
2023-10-17 13:24:37 +00:00
|
|
|
|
gap: 1,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography>
|
|
|
|
|
{nonDeletedQuizQuestions.length > 0
|
|
|
|
|
? `Вопрос ${currentQuizStep + 1} из ${
|
|
|
|
|
nonDeletedQuizQuestions.length
|
|
|
|
|
}`
|
|
|
|
|
: "Нет вопросов"}
|
|
|
|
|
</Typography>
|
|
|
|
|
{nonDeletedQuizQuestions.length > 0 && (
|
|
|
|
|
<LinearProgress
|
|
|
|
|
variant="determinate"
|
|
|
|
|
value={currentProgress}
|
|
|
|
|
sx={{
|
|
|
|
|
"&.MuiLinearProgress-colorPrimary": {
|
|
|
|
|
backgroundColor: "fadePurple.main",
|
|
|
|
|
},
|
|
|
|
|
"& .MuiLinearProgress-barColorPrimary": {
|
|
|
|
|
backgroundColor: "brightPurple.main",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
ml: 2,
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: 1,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
onClick={decrementCurrentQuestionIndex}
|
|
|
|
|
disabled={currentQuizStep === 0}
|
|
|
|
|
sx={{ px: 1, minWidth: 0 }}
|
|
|
|
|
>
|
|
|
|
|
<ArrowLeft />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
onClick={() => incrementCurrentQuestionIndex(maxCurrentQuizStep)}
|
|
|
|
|
disabled={currentQuizStep >= maxCurrentQuizStep}
|
|
|
|
|
>
|
|
|
|
|
Далее
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Paper>
|
|
|
|
|
);
|
2023-10-09 12:33:45 +00:00
|
|
|
|
}
|