diff --git a/src/App.tsx b/src/App.tsx
index a6f4ded1..20a522ae 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -62,7 +62,7 @@ export default function App() {
} />
} />
} />
- } />
+ } />
>
diff --git a/src/model/questionTypes/shared.ts b/src/model/questionTypes/shared.ts
index 6707538e..05524770 100644
--- a/src/model/questionTypes/shared.ts
+++ b/src/model/questionTypes/shared.ts
@@ -17,7 +17,7 @@ export interface QuestionBranchingRuleMain {
or: boolean;
rules: {
question: string; //id родителя (пока что)
- answers: string[]
+ answers: string[]
}[]
}
export interface QuestionBranchingRule {
diff --git a/src/model/quizSettings.ts b/src/model/quizSettings.ts
index 63b88dac..950f80a3 100644
--- a/src/model/quizSettings.ts
+++ b/src/model/quizSettings.ts
@@ -33,7 +33,7 @@ export interface QuizConfig {
noStartPage: boolean;
startpageType: QuizStartpageType;
results: QuizResultsType;
- haveRoot: boolean;
+ haveRoot: string | null;
startpage: {
description: string;
button: string;
@@ -62,7 +62,7 @@ export const defaultQuizConfig: QuizConfig = {
noStartPage: false,
startpageType: null,
results: null,
- haveRoot: false,
+ haveRoot: null,
startpage: {
description: "",
button: "",
diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx
index 27dedde8..5ccb0a98 100644
--- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx
+++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx
@@ -1,7 +1,7 @@
import { MessageIcon } from "@icons/messagIcon";
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
-import { TextareaAutosize } from "@mui/base/TextareaAutosize";
+import TextareaAutosize from "@mui/base/TextareaAutosize";
import {
Box,
FormControl,
diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx
index a988b562..3fb7bb6b 100644
--- a/src/pages/Questions/BranchingMap/CsComponent.tsx
+++ b/src/pages/Questions/BranchingMap/CsComponent.tsx
@@ -3,7 +3,7 @@ import Cytoscape from "cytoscape";
import CytoscapeComponent from "react-cytoscapejs";
import popper from "cytoscape-popper";
import { useCurrentQuiz } from "@root/quizes/hooks";
-import { updateRootInfo } from "@root/quizes/actions"
+import { updateRootContentId } from "@root/quizes/actions"
import { AnyQuizQuestion } from "@model/questionTypes/shared"
import { useQuestionsStore } from "@root/questions/store";
import { cleardragQuestionContentId, updateQuestion, updateOpenedModalSettingsId, getQuestionByContentId } from "@root/questions/actions";
@@ -211,7 +211,7 @@ export const CsComponent = ({
question.content.rule.main = []
question.content.rule.default = ""
})
- updateRootInfo(quiz?.id, false)
+ updateRootContentId(quiz?.id, false)
} else {
console.log("click not ROOT")
const parentQuestionContentId = cy?.$('edge[target = "' + targetNodeContentId + '"]')?.toArray()?.[0]?.data()?.source
diff --git a/src/pages/Questions/BranchingMap/FirstNodeField.tsx b/src/pages/Questions/BranchingMap/FirstNodeField.tsx
index 159dfbeb..3ae599d7 100644
--- a/src/pages/Questions/BranchingMap/FirstNodeField.tsx
+++ b/src/pages/Questions/BranchingMap/FirstNodeField.tsx
@@ -1,7 +1,7 @@
import { Box } from "@mui/material"
import { useEffect, useRef, useState } from "react";
import { updateDragQuestionContentId, updateQuestion } from "@root/questions/actions"
-import { updateRootInfo } from "@root/quizes/actions"
+import { updateRootContentId } from "@root/quizes/actions"
import { useQuestionsStore } from "@root/questions/store"
import { useCurrentQuiz } from "@root/quizes/hooks";
import { enqueueSnackbar } from "notistack";
@@ -23,7 +23,7 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
console.log(dragQuestionContentId)
if (dragQuestionContentId) {
- updateRootInfo(quiz?.id, true)
+ updateRootContentId(quiz?.id, dragQuestionContentId)
updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root")
}
} else {
@@ -44,7 +44,7 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
if (quiz) {
if (modalQuestionTargetContentId) {
- updateRootInfo(quiz?.id, true)
+ updateRootContentId(quiz?.id, modalQuestionTargetContentId)
updateQuestion(modalQuestionTargetContentId, (question) => question.content.rule.parentId = "root")
}
} else {
diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx
index 1a8ba1e3..b8b97d61 100644
--- a/src/pages/ViewPublicationPage/Footer.tsx
+++ b/src/pages/ViewPublicationPage/Footer.tsx
@@ -1,20 +1,20 @@
import { useState, useEffect } from "react";
import { Box, Typography, Button, useTheme } from "@mui/material";
-import { useQuizViewStore } from "@root/quizView";
+import { useQuizViewStore, getAnswersByQuestionId } from "@root/quizView";
-import type { QuizQuestionBase } from "../../model/questionTypes/shared";
+import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questionTypes/shared";
+import { getQuestionByContentId } from "@root/questions/actions";
+import { enqueueSnackbar } from "notistack";
type FooterProps = {
- stepNumber: number;
- setStepNumber: (step: number) => void;
- questions: QuizQuestionBase[];
+ setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
+ question: QuizQuestionBase;
};
export const Footer = ({
- stepNumber,
- setStepNumber,
- questions,
+ setCurrentQuestion,
+ question,
}: FooterProps) => {
const [disabledQuestionsId, setDisabledQuestionsId] = useState>(
new Set()
@@ -22,37 +22,62 @@ export const Footer = ({
const { answers } = useQuizViewStore();
const theme = useTheme();
- useEffect(() => {
- clearDisabledQuestions();
-
- const disabledIds = [] as string[];
-
- const newDisabledIds = new Set([...disabledQuestionsId, ...disabledIds]);
- setDisabledQuestionsId(newDisabledIds);
- }, [answers]);
-
- const clearDisabledQuestions = () => {
- const cleanDisabledQuestions = new Set();
-
- answers.forEach(({ step, answer }) => {
- questions[step - 1].content.rule.main.forEach(({ next, rules }) => {
- rules.forEach(({ answers }) => {
- if (answer !== answers[0]) {
- cleanDisabledQuestions.add(next);
- }
- });
- });
- });
-
- setDisabledQuestionsId(cleanDisabledQuestions);
- };
-
const followPreviousStep = () => {
- setStepNumber(stepNumber - 1);
+ if (question?.content.rule.parentId !== "root") {
+ const parent = getQuestionByContentId(question?.content.rule.parentId)
+ if (parent) {
+ setCurrentQuestion(parent)
+ } else {
+ enqueueSnackbar("не могу получить предыдущий вопрос")
+ }
+ } else {
+ enqueueSnackbar("вы находитесь на первом вопросе")
+ }
};
const followNextStep = () => {
- setStepNumber(stepNumber + 1);
+ const answers = getAnswersByQuestionId(question.content.id) || []
+ console.log(answers)
+ if (answers) {
+
+ let readyBeNextQuestion = ""
+ question.content.rule.main.forEach(({ next, rules }) => {
+ console.log({ next, rules })
+
+ console.log("[storeAnswers] ", rules[0].answers)
+ console.log("[answers.answer] ", [answers.answer])
+
+ let longerArray = Math.max(rules[0].answers.length, [answers.answer].length)
+
+ for (var i = 0; i < longerArray; i++) // Цикл по всем элементам бОльшего массива
+ if (rules[0].answers[i] !== [answers.answer][i]) readyBeNextQuestion = next; // Если хоть один элемент отличается, массивы не равны
+
+
+ })
+ if (readyBeNextQuestion) {
+ console.log("мы нашли совпадение в " + readyBeNextQuestion)
+
+ const nextQuestion = getQuestionByContentId(readyBeNextQuestion)
+ console.log("next question ", nextQuestion)
+ if (nextQuestion) {
+ console.log("я устанавливаю следующий вопрос " + question.title)
+ setCurrentQuestion(nextQuestion)
+ return
+ } else {
+ enqueueSnackbar("не могу получить последующий вопрос")
+ }
+ } else {
+ const nextQuestion = getQuestionByContentId(question.content.rule.default)
+ console.log("я устанавливаю дефолтный вопрос")
+ if (nextQuestion) {
+ setCurrentQuestion(nextQuestion)
+ } else {
+ enqueueSnackbar("не могу получить последующий вопрос (дефолтный)")
+ }
+ }
+
+ }
+
};
return (
@@ -82,7 +107,7 @@ export const Footer = ({
color: theme.palette.grey1.main,
}}
>
- Шаг
+ {/* Шаг
- {stepNumber}
-
- Из
+ {stepNumber} */}
+ {/* */}
+ {/* Из
{questions.length}
-
+ */}