fix: questions multianswer logic
This commit is contained in:
parent
0fbce2ae96
commit
23c1688d01
@ -1,24 +1,28 @@
|
|||||||
import { useParams } from "react-router-dom";
|
|
||||||
import { Box, Modal, Button, Typography } from "@mui/material";
|
import { Box, Modal, Button, Typography } from "@mui/material";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "@model/questionTypes/shared";
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||||
|
|
||||||
type AnyQuestion = UntypedQuizQuestion | AnyTypedQuizQuestion
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
openedModalQuestions: boolean;
|
openedModalQuestions: boolean;
|
||||||
setModalQuestionTargetContentId: (contentId:string) => void;
|
setModalQuestionTargetContentId: (contentId: string) => void;
|
||||||
setOpenedModalQuestions: (open:boolean) => void;
|
setOpenedModalQuestions: (open: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BranchingQuestionsModal = ({ openedModalQuestions, setOpenedModalQuestions, setModalQuestionTargetContentId}:Props) => {
|
export const BranchingQuestionsModal = ({
|
||||||
const quizId = Number(useParams().quizId);
|
openedModalQuestions,
|
||||||
|
setOpenedModalQuestions,
|
||||||
|
setModalQuestionTargetContentId,
|
||||||
|
}: Props) => {
|
||||||
const { questions } = useQuestionsStore();
|
const { questions } = useQuestionsStore();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpenedModalQuestions(false);
|
setOpenedModalQuestions(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const typedQuestions: AnyTypedQuizQuestion[] = questions.filter(
|
||||||
|
(question) => question.type && !question.content.rule.parentId
|
||||||
|
) as AnyTypedQuizQuestion[];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={openedModalQuestions} onClose={handleClose}>
|
<Modal open={openedModalQuestions} onClose={handleClose}>
|
||||||
<Box
|
<Box
|
||||||
@ -37,13 +41,11 @@ export const BranchingQuestionsModal = ({ openedModalQuestions, setOpenedModalQu
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
|
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
|
||||||
{questions.filter((q:AnyQuestion) => {
|
{typedQuestions.map((question) => (
|
||||||
if (q.content === null) return true
|
|
||||||
return (q.type && !q.content.rule.parentId)}).map((question: AnyTypedQuizQuestion, index:number) => (
|
|
||||||
<Button
|
<Button
|
||||||
key={question.content.id}
|
key={question.content.id}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setModalQuestionTargetContentId(question.content.id)
|
setModalQuestionTargetContentId(question.content.id);
|
||||||
handleClose();
|
handleClose();
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
@ -55,9 +55,9 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => {
|
|||||||
i < longerArray;
|
i < longerArray;
|
||||||
i++ // Цикл по всем элементам бОльшего массива
|
i++ // Цикл по всем элементам бОльшего массива
|
||||||
) {
|
) {
|
||||||
debugger;
|
if (rules[0].answers[i] === answers.at(-1)?.answer) {
|
||||||
if (rules[0].answers[i] === answers.at(-1)?.answer)
|
|
||||||
readyBeNextQuestion = next; // Если хоть один элемент отличается, массивы не равны
|
readyBeNextQuestion = next; // Если хоть один элемент отличается, массивы не равны
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (readyBeNextQuestion) {
|
if (readyBeNextQuestion) {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { devtools } from "zustand/middleware";
|
|||||||
|
|
||||||
|
|
||||||
export type QuestionsStore = {
|
export type QuestionsStore = {
|
||||||
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion);
|
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion)[];
|
||||||
openedModalSettingsId: string | null;
|
openedModalSettingsId: string | null;
|
||||||
dragQuestionContentId: string | null;
|
dragQuestionContentId: string | null;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user