From 0890d5a67c869cd9227bff0f0b89ccb417455e62 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Tue, 5 Dec 2023 22:55:21 +0300 Subject: [PATCH 01/70] feat: Branching Data logic --- src/pages/Questions/BranchingModal/Settings.tsx | 8 ++++---- src/pages/Questions/ButtonsOptions.tsx | 3 ++- src/pages/ViewPublicationPage/questions/Date.tsx | 7 ++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pages/Questions/BranchingModal/Settings.tsx b/src/pages/Questions/BranchingModal/Settings.tsx index 975c1a9e..a5db68d4 100644 --- a/src/pages/Questions/BranchingModal/Settings.tsx +++ b/src/pages/Questions/BranchingModal/Settings.tsx @@ -10,7 +10,7 @@ import { AnyTypedQuizQuestion } from "../../../model/questionTypes/shared" import { SelectChangeEvent } from '@mui/material/Select'; import CalendarIcon from "@icons/CalendarIcon"; import { DatePicker } from "@mui/x-date-pickers"; -import * as dayjs from 'dayjs' +import dayjs from 'dayjs' import { TimePicker } from '@mui/x-date-pickers/TimePicker'; import InfoIcon from "@icons/Info"; import { DeleteIcon } from "@icons/questionsPage/deleteIcon"; @@ -289,12 +289,12 @@ const DateInputsType = ({ parentQuestion, targetQuestion, ruleIndex, setParentQu } { - const date = dateString?.$d?.toLocaleDateString("ru-RU", { year: "numeric", month: "2-digit", day: "2-digit" }); + const date = dateString?.toDate().toLocaleDateString("ru-RU", { year: "numeric", month: "2-digit", day: "2-digit" }); let newParentQuestion = JSON.parse(JSON.stringify(parentQuestion)) newParentQuestion.content.rule.main[ruleIndex].rules[0].answers = [date] - // setParentQuestion(newParentQuestion) + setParentQuestion(newParentQuestion) }} slots={{ openPickerIcon: () => , diff --git a/src/pages/Questions/ButtonsOptions.tsx b/src/pages/Questions/ButtonsOptions.tsx index 929372d2..a2472488 100644 --- a/src/pages/Questions/ButtonsOptions.tsx +++ b/src/pages/Questions/ButtonsOptions.tsx @@ -56,7 +56,8 @@ const {openBranchingPanel} = useQuestionsStore.getState() return enqueueSnackbar("У корня нет условий ветвления") } if (parentId.length !== 0) { - updateOpenBranchingPanel(value) + // updateOpenBranchingPanel(value) + openedModal() } } diff --git a/src/pages/ViewPublicationPage/questions/Date.tsx b/src/pages/ViewPublicationPage/questions/Date.tsx index 115d1201..ff64a02c 100644 --- a/src/pages/ViewPublicationPage/questions/Date.tsx +++ b/src/pages/ViewPublicationPage/questions/Date.tsx @@ -17,6 +17,7 @@ export const Date = ({ currentQuestion }: DateProps) => { answers.find( ({ questionId }) => questionId === currentQuestion.content.id ) ?? {}; + const [day, month, year] = answer?.split(".") || []; return ( @@ -30,7 +31,11 @@ export const Date = ({ currentQuestion }: DateProps) => { }} > updateAnswer( currentQuestion.content.id, From 82d43a3beaf866c44428065cb6d8bc23697114bc Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Wed, 6 Dec 2023 15:09:25 +0300 Subject: [PATCH 02/70] feat: View linear logic --- .../DraggableList/QuestionPageCard.tsx | 2 +- src/pages/ViewPublicationPage/Footer.tsx | 82 ++++++++++++++++--- src/pages/ViewPublicationPage/Question.tsx | 29 +++++-- 3 files changed, 91 insertions(+), 22 deletions(-) diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index 34de3139..2bfad5f3 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -68,7 +68,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging return ( <> void; question: QuizQuestionBase; }; -export const Footer = ({ setCurrentQuestion, question }: FooterProps) => { +export const Footer = ({ + setCurrentQuestion, + questions, + question, +}: FooterProps) => { const [disabledQuestionsId, setDisabledQuestionsId] = useState>( new Set() ); @@ -24,28 +29,55 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => { const [disableNextButton, setDisableNextButton] = useState(false); const { answers } = useQuizViewStore(); const theme = useTheme(); + const linear = !questions.find( + ({ content }) => content.rule.parentId === "root" + ); useEffect(() => { // Логика для аргумента disabled у кнопки "Назад" - if (question?.content.rule.parentId === "root") { - setDisablePreviousButton(true); + if (linear) { + const questionIndex = questions.findIndex(({ id }) => id === question.id); + + const previousQuestion = questions[questionIndex - 1]; + + if (previousQuestion) { + setDisablePreviousButton(false); + } else { + setDisablePreviousButton(true); + } } else { - setDisablePreviousButton(false); + if (question?.content.rule.parentId === "root") { + setDisablePreviousButton(true); + } else { + setDisablePreviousButton(false); + } } // Логика для аргумента disabled у кнопки "Далее" - const nextQuestionId = getNextQuestionId(); - if (nextQuestionId) { - setDisableNextButton(false); - } else { - const nextQuestion = getQuestionByContentId( - question.content.rule.default - ); - if (nextQuestion?.type) { + if (linear) { + const questionIndex = questions.findIndex(({ id }) => id === question.id); + + const nextQuestion = questions[questionIndex + 1]; + + if (nextQuestion) { setDisableNextButton(false); } else { setDisableNextButton(true); } + } else { + const nextQuestionId = getNextQuestionId(); + if (nextQuestionId) { + setDisableNextButton(false); + } else { + const nextQuestion = getQuestionByContentId( + question.content.rule.default + ); + if (nextQuestion?.type) { + setDisableNextButton(false); + } else { + setDisableNextButton(true); + } + } } }, [question]); @@ -79,6 +111,18 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => { }; const followPreviousStep = () => { + if (linear) { + const questionIndex = questions.findIndex(({ id }) => id === question.id); + + const previousQuestion = questions[questionIndex - 1]; + + if (previousQuestion) { + setCurrentQuestion(previousQuestion); + } + + return; + } + if (question?.content.rule.parentId !== "root") { const parent = getQuestionByContentId(question?.content.rule.parentId); if (parent?.type) { @@ -92,6 +136,18 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => { }; const followNextStep = () => { + if (linear) { + const questionIndex = questions.findIndex(({ id }) => id === question.id); + + const nextQuestion = questions[questionIndex + 1]; + + if (nextQuestion) { + setCurrentQuestion(nextQuestion); + } + + return; + } + const nextQuestionId = getNextQuestionId(); if (nextQuestionId) { diff --git a/src/pages/ViewPublicationPage/Question.tsx b/src/pages/ViewPublicationPage/Question.tsx index a46fc60c..494ec11e 100644 --- a/src/pages/ViewPublicationPage/Question.tsx +++ b/src/pages/ViewPublicationPage/Question.tsx @@ -13,11 +13,11 @@ import { Page } from "./questions/Page"; import { Rating } from "./questions/Rating"; import { Footer } from "./Footer"; -import { useState, type FC } from "react"; +import { useState, type FC, useEffect } from "react"; import type { QuestionType } from "../../model/question/question"; import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; import { useCurrentQuiz } from "@root/quizes/hooks"; - import { getQuestionByContentId } from "@root/questions/actions"; +import { getQuestionByContentId } from "@root/questions/actions"; type QuestionProps = { stepNumber: number; @@ -39,12 +39,24 @@ const QUESTIONS_MAP: any = { rating: Rating, }; -export const Question = ({ - questions, -}: QuestionProps) => { +export const Question = ({ questions }: QuestionProps) => { const quiz = useCurrentQuiz(); - const [currentQuestion, setCurrentQuestion] = useState(getQuestionByContentId(quiz?.config.haveRoot || "")) - if (!currentQuestion) return <>не смог отобразить вопрос + const [currentQuestion, setCurrentQuestion] = + useState(); + + useEffect(() => { + const nextQuestion = getQuestionByContentId(quiz?.config.haveRoot || ""); + + if (nextQuestion?.type) { + setCurrentQuestion(nextQuestion); + + return; + } + + setCurrentQuestion(questions[0]); + }, []); + + if (!currentQuestion) return <>не смог отобразить вопрос; const QuestionComponent = QUESTIONS_MAP[currentQuestion.type as Exclude]; @@ -60,9 +72,10 @@ export const Question = ({ margin: "0 auto", }} > - +