fix: View next button with multiselect

This commit is contained in:
IlyaDoronin 2023-12-14 17:05:19 +03:00
parent 9aec2d8e86
commit 18750c1699

@ -3,7 +3,10 @@ import { Box, Button, useTheme } from "@mui/material";
import { useQuizViewStore } from "@root/quizView"; import { useQuizViewStore } from "@root/quizView";
import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questionTypes/shared"; import type {
AnyTypedQuizQuestion,
QuizQuestionBase,
} from "../../model/questionTypes/shared";
import { getQuestionByContentId } from "@root/questions/actions"; import { getQuestionByContentId } from "@root/questions/actions";
import { enqueueSnackbar } from "notistack"; import { enqueueSnackbar } from "notistack";
@ -103,22 +106,34 @@ export const Footer = ({
let readyBeNextQuestion = ""; let readyBeNextQuestion = "";
(question as QuizQuestionBase).content.rule.main.forEach(({ next, rules }) => { (question as QuizQuestionBase).content.rule.main.forEach(
let longerArray = Math.max( ({ next, rules }) => {
rules[0].answers.length, let longerArray = Math.max(
[answer?.answer].length rules[0].answers.length,
); answer?.answer && Array.isArray(answer?.answer)
? answer?.answer.length
: [answer?.answer].length
);
for ( for (
var i = 0; var i = 0;
i < longerArray; i < longerArray;
i++ // Цикл по всем эле­мен­там бОльшего массива i++ // Цикл по всем эле­мен­там бОльшего массива
) { ) {
if (rules[0].answers[i] === answer?.answer) { if (Array.isArray(answer?.answer)) {
readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны if (answer?.answer.find((item) => item === rules[0].answers[i])) {
readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны
}
return;
}
if (rules[0].answers[i] === answer?.answer) {
readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны
}
} }
} }
}); );
return readyBeNextQuestion; return readyBeNextQuestion;
} }