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