import { useState, useEffect } from "react"; import { Box, Typography, Button, useTheme } from "@mui/material"; import { useQuizViewStore } from "@root/quizView"; import type { AnyTypedQuizQuestion, QuizQuestionBase, } from "../../model/questionTypes/shared"; import { getQuestionByContentId } from "@root/questions/actions"; import { enqueueSnackbar } from "notistack"; type FooterProps = { setCurrentQuestion: (step: AnyTypedQuizQuestion) => void; question: QuizQuestionBase; }; export const Footer = ({ setCurrentQuestion, question }: FooterProps) => { const [disabledQuestionsId, setDisabledQuestionsId] = useState>( new Set() ); const { answers } = useQuizViewStore(); const theme = useTheme(); const followPreviousStep = () => { if (question?.content.rule.parentId !== "root") { const parent = getQuestionByContentId(question?.content.rule.parentId); if (parent) { setCurrentQuestion(parent); } else { enqueueSnackbar("не могу получить предыдущий вопрос"); } } else { enqueueSnackbar("вы находитесь на первом вопросе"); } }; const followNextStep = () => { if (answers.length) { let readyBeNextQuestion = ""; question.content.rule.main.forEach(({ next, rules }) => { console.log({ next, rules }); console.log("[storeAnswers] ", rules[0].answers); console.log("[answers.answer] ", [answers.at(-1)?.answer]); let longerArray = Math.max( rules[0].answers.length, [answers.at(-1)?.answer].length ); for ( var i = 0; i < longerArray; i++ // Цикл по всем эле­мен­там бОльшего массива ) { debugger; if (rules[0].answers[i] === answers.at(-1)?.answer) readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны } }); 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("не могу получить последующий вопрос (дефолтный)"); } } } }; return ( {/* Шаг {stepNumber} */} {/* */} {/* Из {questions.length} */} ); };