From 71f749e892f5f11bd77f410718a22d1f670e96c2 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Tue, 31 Oct 2023 12:59:41 +0300 Subject: [PATCH] fix: branching error --- src/constants/base.ts | 1 + src/model/questionTypes/shared.ts | 1 + src/pages/Questions/ButtonsOptions.tsx | 7 ++++--- src/pages/Questions/ButtonsOptionsAndPict.tsx | 5 +++-- src/pages/Questions/branchingQuestions.tsx | 21 +++++++------------ src/stores/questions.ts | 6 ------ 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/constants/base.ts b/src/constants/base.ts index 63e491e0..2660041c 100644 --- a/src/constants/base.ts +++ b/src/constants/base.ts @@ -4,6 +4,7 @@ export const QUIZ_QUESTION_BASE: Omit = { title: "", type: "nonselected", expanded: true, + openedModalSettings: false, required: false, deleted: false, deleteTimeoutId: 0, diff --git a/src/model/questionTypes/shared.ts b/src/model/questionTypes/shared.ts index c5fd91a5..b3761dbb 100644 --- a/src/model/questionTypes/shared.ts +++ b/src/model/questionTypes/shared.ts @@ -48,6 +48,7 @@ export interface QuizQuestionBase { title: string; type: string; expanded: boolean; + openedModalSettings: boolean; required: boolean; deleted: boolean; deleteTimeoutId: number; diff --git a/src/pages/Questions/ButtonsOptions.tsx b/src/pages/Questions/ButtonsOptions.tsx index f83973a1..46d53a1f 100644 --- a/src/pages/Questions/ButtonsOptions.tsx +++ b/src/pages/Questions/ButtonsOptions.tsx @@ -17,7 +17,6 @@ import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon"; import { questionStore, - resetSomeField, copyQuestion, removeQuestionForce, updateQuestionsList, @@ -45,7 +44,7 @@ export default function ButtonsOptions({ totalIndex, }: Props) { const quizId = Number(useParams().quizId); - const { openedModalSettings, listQuestions } = questionStore(); + const { listQuestions } = questionStore(); const { listQuizes } = quizStore(); const [openedReallyChangingModal, setOpenedReallyChangingModal] = useState(false); @@ -59,7 +58,9 @@ export default function ButtonsOptions({ }, [listQuestions]); const openedModal = () => { - resetSomeField({ openedModalSettings: "open" }); + updateQuestionsList(quizId, totalIndex, { + openedModalSettings: true, + }); }; const theme = useTheme(); diff --git a/src/pages/Questions/ButtonsOptionsAndPict.tsx b/src/pages/Questions/ButtonsOptionsAndPict.tsx index fc59b983..b636101b 100644 --- a/src/pages/Questions/ButtonsOptionsAndPict.tsx +++ b/src/pages/Questions/ButtonsOptionsAndPict.tsx @@ -21,7 +21,6 @@ import { questionStore, copyQuestion, removeQuestion, - resetSomeField, removeQuestionForce, updateQuestionsList, } from "@root/questions"; @@ -62,7 +61,9 @@ export default function ButtonsOptionsAndPict({ }, [listQuestions]); const openedModal = () => { - resetSomeField({ openedModalSettings: "open" }); + updateQuestionsList(quizId, totalIndex, { + openedModalSettings: true, + }); }; return ( diff --git a/src/pages/Questions/branchingQuestions.tsx b/src/pages/Questions/branchingQuestions.tsx index 7578d2a2..4283523f 100644 --- a/src/pages/Questions/branchingQuestions.tsx +++ b/src/pages/Questions/branchingQuestions.tsx @@ -15,11 +15,7 @@ import { Typography, useTheme, } from "@mui/material"; -import { - questionStore, - resetSomeField, - updateQuestionsList, -} from "@root/questions"; +import { questionStore, updateQuestionsList } from "@root/questions"; import { Select } from "./Select"; import RadioCheck from "@ui_kit/RadioCheck"; @@ -48,7 +44,7 @@ export default function BranchingQuestions({ const [title, setTitle] = useState(""); const [titleInputWidth, setTitleInputWidth] = useState(0); const quizId = Number(useParams().quizId); - const { openedModalSettings, listQuestions } = questionStore(); + const { listQuestions } = questionStore(); const titleRef = useRef(null); const question = listQuestions[quizId][totalIndex] as QuizQuestionBase; @@ -57,20 +53,17 @@ export default function BranchingQuestions({ }, [title]); const handleClose = () => { - resetSomeField({ openedModalSettings: "" }); + updateQuestionsList(quizId, totalIndex, { + openedModalSettings: false, + }); }; return ( <> - + ; - openedModalSettings: string; } let isFirstPartialize = true; @@ -34,7 +33,6 @@ export const questionStore = create()( devtools( () => ({ listQuestions: {}, - openedModalSettings: "", }), { name: "Question", @@ -341,10 +339,6 @@ export const removeQuestion = (quizId: number, index: number) => { questionStore.setState({ listQuestions: questionListClone }); }; -export const resetSomeField = (data: Record) => { - questionStore.setState(data); -}; - export const findQuestionById = (quizId: number) => { let found = null; questionStore