fix: questions multianswer logic

This commit is contained in:
IlyaDoronin 2023-12-04 16:36:30 +03:00
parent 0fbce2ae96
commit 23c1688d01
3 changed files with 17 additions and 15 deletions

@ -1,24 +1,28 @@
import { useParams } from "react-router-dom";
import { Box, Modal, Button, Typography } from "@mui/material";
import { useQuestionsStore } from "@root/questions/store";
import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "@model/questionTypes/shared";
type AnyQuestion = UntypedQuizQuestion | AnyTypedQuizQuestion
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
interface Props {
openedModalQuestions: boolean;
setModalQuestionTargetContentId: (contentId:string) => void;
setOpenedModalQuestions: (open:boolean) => void;
setModalQuestionTargetContentId: (contentId: string) => void;
setOpenedModalQuestions: (open: boolean) => void;
}
export const BranchingQuestionsModal = ({ openedModalQuestions, setOpenedModalQuestions, setModalQuestionTargetContentId}:Props) => {
const quizId = Number(useParams().quizId);
export const BranchingQuestionsModal = ({
openedModalQuestions,
setOpenedModalQuestions,
setModalQuestionTargetContentId,
}: Props) => {
const { questions } = useQuestionsStore();
const handleClose = () => {
setOpenedModalQuestions(false);
};
const typedQuestions: AnyTypedQuizQuestion[] = questions.filter(
(question) => question.type && !question.content.rule.parentId
) as AnyTypedQuizQuestion[];
return (
<Modal open={openedModalQuestions} onClose={handleClose}>
<Box
@ -37,13 +41,11 @@ export const BranchingQuestionsModal = ({ openedModalQuestions, setOpenedModalQu
}}
>
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
{questions.filter((q:AnyQuestion) => {
if (q.content === null) return true
return (q.type && !q.content.rule.parentId)}).map((question: AnyTypedQuizQuestion, index:number) => (
{typedQuestions.map((question) => (
<Button
key={question.content.id}
onClick={() => {
setModalQuestionTargetContentId(question.content.id)
setModalQuestionTargetContentId(question.content.id);
handleClose();
}}
sx={{

@ -55,9 +55,9 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => {
i < longerArray;
i++ // Цикл по всем эле­мен­там бОльшего массива
) {
debugger;
if (rules[0].answers[i] === answers.at(-1)?.answer)
if (rules[0].answers[i] === answers.at(-1)?.answer) {
readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны
}
}
});
if (readyBeNextQuestion) {

@ -4,7 +4,7 @@ import { devtools } from "zustand/middleware";
export type QuestionsStore = {
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion);
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion)[];
openedModalSettingsId: string | null;
dragQuestionContentId: string | null;
};