From 319d321a6a9b0cf2995c92d09f5f97ff382d1132 Mon Sep 17 00:00:00 2001 From: aleksandr-raw <104529174+aleksandr-raw@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:25:21 +0400 Subject: [PATCH] reset data after leaving the page --- .../Questions/BranchingMap/CsNodeButtons.tsx | 34 +++++++++++-------- src/pages/Questions/BranchingMap/helper.ts | 21 +++++++----- src/pages/QuizAnswersPage/QuizAnswersPage.tsx | 4 +++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/pages/Questions/BranchingMap/CsNodeButtons.tsx b/src/pages/Questions/BranchingMap/CsNodeButtons.tsx index 6c6b7656..bbeaf5e6 100644 --- a/src/pages/Questions/BranchingMap/CsNodeButtons.tsx +++ b/src/pages/Questions/BranchingMap/CsNodeButtons.tsx @@ -80,18 +80,19 @@ export default function CsNodeButtons({ csElements, cyRef }: Props) { cleardragQuestionContentId(); }} />, - (!csElement.data.isRoot && !isQuestionProhibited(csElement.data.qtype)) && ( - { - const buttonData = buttonRefsById.current[csElement.data.id]; - if (buttonData) buttonData.settings = r; - }} - onClick={() => { - updateOpenedModalSettingsId(csElement.data.id,); - }} - /> - ), + !csElement.data.isRoot && + !isQuestionProhibited(csElement.data.qtype) && ( + { + const buttonData = buttonRefsById.current[csElement.data.id]; + if (buttonData) buttonData.settings = r; + }} + onClick={() => { + updateOpenedModalSettingsId(csElement.data.id); + }} + /> + ), //оболочка узла { setModalQuestionParentContentId(csElement.data.id); - console.log("csElement ", csElement) - setOpenedModalQuestions(!(isQuestionProhibited(csElement.data.type) && csElement.data.children > 0)); + console.log("csElement ", csElement); + setOpenedModalQuestions( + !( + isQuestionProhibited(csElement.data.type) && + csElement.data.children > 0 + ), + ); }} />, ])} diff --git a/src/pages/Questions/BranchingMap/helper.ts b/src/pages/Questions/BranchingMap/helper.ts index 94d59e60..adf021f3 100644 --- a/src/pages/Questions/BranchingMap/helper.ts +++ b/src/pages/Questions/BranchingMap/helper.ts @@ -73,9 +73,12 @@ export const storeToNodes = (questions: AnyTypedQuizQuestion[]) => { isRoot: question.content.rule.parentId === "root", id: question.content.id, label, - qtype: question.content.rule.parentId === "root" ? "root" : parentQuestion.type, + qtype: + question.content.rule.parentId === "root" + ? "root" + : parentQuestion.type, type: question.type, - children: question.content.rule.children.length + children: question.content.rule.children.length, }, classes: "multiline-auto", }); @@ -344,14 +347,15 @@ export const addNode = ({ const parentQuestion = { ...getQuestionByContentId(parentNodeContentId), } as AnyTypedQuizQuestion; - if ((parentQuestion.type !== undefined && isQuestionProhibited(parentQuestion.type)) && + if ( + parentQuestion.type !== undefined && + isQuestionProhibited(parentQuestion.type) && parentQuestion.content.rule.children.length > 0 ) { enqueueSnackbar("у вопроса этого типа может быть только 1 потомок"); return; } - //если есть инфо о выбранном вопросе из модалки - берём родителя из инфо модалки. Иначе из значения дропа const targetQuestion = { ...getQuestionByContentId( @@ -363,13 +367,14 @@ export const addNode = ({ clearDataAfterAddNode({ parentNodeContentId, targetQuestion }); createResult(useQuizStore.getState().editQuizId, targetQuestion.content.id); } else { - enqueueSnackbar("Добавляемый вопрос не найден. Перетащите вопрос из списка"); + enqueueSnackbar( + "Добавляемый вопрос не найден. Перетащите вопрос из списка", + ); } }; -export const isQuestionProhibited = (parentQType: string) => ( +export const isQuestionProhibited = (parentQType: string) => parentQType === "text" || parentQType === "date" || parentQType === "number" || - parentQType === "page" -) + parentQType === "page"; diff --git a/src/pages/QuizAnswersPage/QuizAnswersPage.tsx b/src/pages/QuizAnswersPage/QuizAnswersPage.tsx index 103e839e..8afbf8e1 100644 --- a/src/pages/QuizAnswersPage/QuizAnswersPage.tsx +++ b/src/pages/QuizAnswersPage/QuizAnswersPage.tsx @@ -126,6 +126,10 @@ export const QuizAnswersPage: FC = () => { ); + useEffect(() => { + return setResults([]); + }, []); + return (