2023-11-30 17:39:57 +00:00
|
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
import { Box, Typography, Button, useTheme } from "@mui/material";
|
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
import { useQuizViewStore, getAnswersByQuestionId } from "@root/quizView";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questionTypes/shared";
|
|
|
|
|
import { getQuestionByContentId } from "@root/questions/actions";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
|
|
type FooterProps = {
|
2023-12-03 10:48:00 +00:00
|
|
|
|
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
|
|
|
|
|
question: QuizQuestionBase;
|
2023-11-30 17:39:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const Footer = ({
|
2023-12-03 10:48:00 +00:00
|
|
|
|
setCurrentQuestion,
|
|
|
|
|
question,
|
2023-11-30 17:39:57 +00:00
|
|
|
|
}: FooterProps) => {
|
|
|
|
|
const [disabledQuestionsId, setDisabledQuestionsId] = useState<Set<string>>(
|
|
|
|
|
new Set()
|
|
|
|
|
);
|
|
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
const followPreviousStep = () => {
|
|
|
|
|
if (question?.content.rule.parentId !== "root") {
|
|
|
|
|
const parent = getQuestionByContentId(question?.content.rule.parentId)
|
|
|
|
|
if (parent) {
|
|
|
|
|
setCurrentQuestion(parent)
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("не могу получить предыдущий вопрос")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("вы находитесь на первом вопросе")
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
const followNextStep = () => {
|
|
|
|
|
const answers = getAnswersByQuestionId(question.content.id) || []
|
|
|
|
|
console.log(answers)
|
|
|
|
|
if (answers) {
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
let readyBeNextQuestion = ""
|
|
|
|
|
question.content.rule.main.forEach(({ next, rules }) => {
|
|
|
|
|
console.log({ next, rules })
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
console.log("[storeAnswers] ", rules[0].answers)
|
|
|
|
|
console.log("[answers.answer] ", [answers.answer])
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
let longerArray = Math.max(rules[0].answers.length, [answers.answer].length)
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
for (var i = 0; i < longerArray; i++) // Цикл по всем элементам бОльшего массива
|
|
|
|
|
if (rules[0].answers[i] !== [answers.answer][i]) readyBeNextQuestion = next; // Если хоть один элемент отличается, массивы не равны
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
})
|
|
|
|
|
if (readyBeNextQuestion) {
|
|
|
|
|
console.log("мы нашли совпадение в " + readyBeNextQuestion)
|
|
|
|
|
|
|
|
|
|
const nextQuestion = getQuestionByContentId(readyBeNextQuestion)
|
|
|
|
|
console.log("next question ", nextQuestion)
|
|
|
|
|
if (nextQuestion) {
|
|
|
|
|
console.log("я устанавливаю следующий вопрос " + question.title)
|
|
|
|
|
setCurrentQuestion(nextQuestion)
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("не могу получить последующий вопрос")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const nextQuestion = getQuestionByContentId(question.content.rule.default)
|
|
|
|
|
console.log("я устанавливаю дефолтный вопрос")
|
|
|
|
|
if (nextQuestion) {
|
|
|
|
|
setCurrentQuestion(nextQuestion)
|
|
|
|
|
} else {
|
|
|
|
|
enqueueSnackbar("не могу получить последующий вопрос (дефолтный)")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:39:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "15px 0",
|
|
|
|
|
borderTop: `1px solid ${theme.palette.grey[400]}`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
maxWidth: "1000px",
|
|
|
|
|
padding: "0 10px",
|
|
|
|
|
margin: "0 auto",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
marginRight: "auto",
|
|
|
|
|
color: theme.palette.grey1.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-03 10:48:00 +00:00
|
|
|
|
{/* <Typography>Шаг</Typography>
|
2023-11-30 17:39:57 +00:00
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
borderRadius: "50%",
|
|
|
|
|
width: "30px",
|
|
|
|
|
height: "30px",
|
|
|
|
|
color: "#FFF",
|
|
|
|
|
background: theme.palette.brightPurple.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-03 10:48:00 +00:00
|
|
|
|
{stepNumber} */}
|
|
|
|
|
{/* </Typography> */}
|
|
|
|
|
{/* <Typography>Из</Typography>
|
2023-11-30 17:39:57 +00:00
|
|
|
|
<Typography sx={{ fontWeight: "bold" }}>
|
|
|
|
|
{questions.length}
|
2023-12-03 10:48:00 +00:00
|
|
|
|
</Typography> */}
|
2023-11-30 17:39:57 +00:00
|
|
|
|
</Box>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{ fontSize: "16px", padding: "10px 15px" }}
|
|
|
|
|
onClick={followPreviousStep}
|
|
|
|
|
>
|
|
|
|
|
← Назад
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{ fontSize: "16px", padding: "10px 15px" }}
|
|
|
|
|
onClick={followNextStep}
|
|
|
|
|
>
|
|
|
|
|
Далее →
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|