From 18750c169980cf461abe723a2ca29f085d3b691e Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 14 Dec 2023 17:05:19 +0300 Subject: [PATCH] fix: View next button with multiselect --- src/pages/ViewPublicationPage/Footer.tsx | 43 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index 8e473c18..dae14e73 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -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,22 +106,34 @@ export const Footer = ({ let readyBeNextQuestion = ""; - (question as QuizQuestionBase).content.rule.main.forEach(({ next, rules }) => { - let longerArray = Math.max( - rules[0].answers.length, - [answer?.answer].length - ); + (question as QuizQuestionBase).content.rule.main.forEach( + ({ next, rules }) => { + let longerArray = Math.max( + rules[0].answers.length, + answer?.answer && Array.isArray(answer?.answer) + ? answer?.answer.length + : [answer?.answer].length + ); - for ( - var i = 0; - i < longerArray; - i++ // Цикл по всем эле­мен­там бОльшего массива - ) { - if (rules[0].answers[i] === answer?.answer) { - readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны + for ( + var i = 0; + 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; }