From e1b9ada5af3156f14a6e17a63b4f769217f918e1 Mon Sep 17 00:00:00 2001 From: Nastya Date: Sun, 3 Dec 2023 13:48:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B2=D0=B5=D1=82=D0=B2=D0=B8=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B2=20=D0=B2=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= =?UTF-8?q?=D1=85=20-=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- src/model/questionTypes/shared.ts | 2 +- src/model/quizSettings.ts | 4 +- .../AnswerDraggableList/AnswerItem.tsx | 2 +- .../Questions/BranchingMap/CsComponent.tsx | 4 +- .../Questions/BranchingMap/FirstNodeField.tsx | 6 +- src/pages/ViewPublicationPage/Footer.tsx | 107 +++++++++++------- src/pages/ViewPublicationPage/Question.tsx | 26 ++--- .../StartPageViewPublication.tsx | 12 +- src/pages/ViewPublicationPage/index.tsx | 23 ++-- .../ViewPublicationPage/questions/Date.tsx | 11 +- .../ViewPublicationPage/questions/Emoji.tsx | 21 ++-- .../ViewPublicationPage/questions/File.tsx | 13 +-- .../ViewPublicationPage/questions/Images.tsx | 21 ++-- .../ViewPublicationPage/questions/Number.tsx | 21 ++-- .../ViewPublicationPage/questions/Page.tsx | 17 ++- .../ViewPublicationPage/questions/Rating.tsx | 19 ++-- .../ViewPublicationPage/questions/Select.tsx | 13 +-- .../ViewPublicationPage/questions/Text.tsx | 13 +-- .../ViewPublicationPage/questions/Variant.tsx | 24 ++-- .../ViewPublicationPage/questions/Varimg.tsx | 27 +++-- src/pages/startPage/StartPage.tsx | 2 +- src/stores/quizView.ts | 16 ++- src/stores/quizes/actions.ts | 4 +- 24 files changed, 212 insertions(+), 198 deletions(-) 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} - + */}