From 149c618597f22b27a921857f9b3ea2de12f71432 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Wed, 4 Oct 2023 12:45:51 +0300 Subject: [PATCH] refactor: clonedContent --- .../AnswerDraggableList/AnswerItem.tsx | 2 +- .../DraggableList/QuestionPageCard.tsx | 9 +- src/pages/Questions/Emoji/Emoji.tsx | 5 +- .../OptionsAndPicture/OptionsAndPicture.tsx | 18 +- .../OptionsPicture/OptionsPicture.tsx | 6 +- .../OwnTextField/settingTextField.tsx | 4 +- .../Questions/RatingOptions/settingRating.tsx | 2 +- .../Questions/SliderOptions/settingSlider.tsx | 2 +- src/pages/Questions/TypeQuestions.tsx | 1 - .../Questions/answerOptions/AnswerOptions.tsx | 5 +- src/pages/Questions/branchingQuestions.tsx | 270 +++++++++--------- src/pages/Questions/helpQuestions.tsx | 4 +- src/stores/questions.ts | 22 +- 13 files changed, 166 insertions(+), 184 deletions(-) diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx index 97f17f4a..a77265ed 100644 --- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx +++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx @@ -175,7 +175,7 @@ export const AnswerItem = ({ updateQuestionsList(quizId, totalIndex, { content: { - ...listQuestions[quizId][totalIndex].content, + ...question.content, variants: cloneVariants, }, }); diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index 3cddbf19..69c7a9d1 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -150,8 +150,11 @@ export default function QuestionsPageCard({ const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobile = useMediaQuery(theme.breakpoints.down(790)); const { listQuestions } = questionStore(); - const { type: switchState, expanded: isExpanded } = - listQuestions[quizId][totalIndex]; + const { + title, + type: switchState, + expanded: isExpanded, + } = listQuestions[quizId][totalIndex]; const anchorRef = useRef(null); const debounced = useDebouncedCallback((title) => { updateQuestionsList(quizId, totalIndex, { title }); @@ -187,7 +190,7 @@ export default function QuestionsPageCard({ }} > debounced(target.value)} InputProps={{ diff --git a/src/pages/Questions/Emoji/Emoji.tsx b/src/pages/Questions/Emoji/Emoji.tsx index 143f4a0a..5ea24328 100644 --- a/src/pages/Questions/Emoji/Emoji.tsx +++ b/src/pages/Questions/Emoji/Emoji.tsx @@ -43,10 +43,7 @@ export default function Emoji({ totalIndex }: Props) { answerNew.push({ answer: "", hints: "", extendedText: "" }); updateQuestionsList(quizId, totalIndex, { - content: { - ...listQuestions[quizId][totalIndex].content, - variants: answerNew, - }, + content: { ...question.content, variants: answerNew }, }); }} > diff --git a/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx b/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx index a25cebb5..c0f2b723 100644 --- a/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx +++ b/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx @@ -61,14 +61,14 @@ export default function OptionsAndPicture({ totalIndex }: Props) { { if (target.files?.length) { - const clonContent = { ...question.content }; + const clonedContent = { ...question.content }; - clonContent.variants[index].answer = URL.createObjectURL( + clonedContent.variants[index].answer = URL.createObjectURL( target.files[0] ); updateQuestionsList(quizId, totalIndex, { - content: clonContent, + content: clonedContent, }); } }} @@ -196,9 +196,15 @@ export default function OptionsAndPicture({ totalIndex }: Props) { variant="body2" sx={{ color: theme.palette.brightPurple.main }} onClick={() => { - const clonContent = { ...question.content }; - clonContent.variants.push({ answer: "", hints: "", extendedText: "" }); - updateQuestionsList(quizId, totalIndex, { content: clonContent }); + const clonedContent = { ...question.content }; + clonedContent.variants.push({ + answer: "", + hints: "", + extendedText: "", + }); + updateQuestionsList(quizId, totalIndex, { + content: clonedContent, + }); }} > Добавьте ответ diff --git a/src/pages/Questions/OptionsPicture/OptionsPicture.tsx b/src/pages/Questions/OptionsPicture/OptionsPicture.tsx index 54070a89..05f1ebe1 100644 --- a/src/pages/Questions/OptionsPicture/OptionsPicture.tsx +++ b/src/pages/Questions/OptionsPicture/OptionsPicture.tsx @@ -48,12 +48,12 @@ export default function OptionsPicture({ totalIndex }: Props) { const addImage = ({ target }: ChangeEvent) => { // if (target.files?.length) { - // const clonContent = question.content; + // const clonedContent = { ...question.content }; - // clonContent.images.push(URL.createObjectURL(target.files[0])); + // clonedContent.images.push(URL.createObjectURL(target.files[0])); // updateQuestionsList(quizId, totalIndex, { - // content: { ...question.content, images }, + // content: clonedContent, // }); // } }; diff --git a/src/pages/Questions/OwnTextField/settingTextField.tsx b/src/pages/Questions/OwnTextField/settingTextField.tsx index 7513743e..0a0864c9 100644 --- a/src/pages/Questions/OwnTextField/settingTextField.tsx +++ b/src/pages/Questions/OwnTextField/settingTextField.tsx @@ -83,7 +83,7 @@ export default function SettingTextField({ } })} onChange={({ target }: React.ChangeEvent) => { - const clonContent = { + const clonedContent = { ...question.content, single: false, multi: false, @@ -91,7 +91,7 @@ export default function SettingTextField({ [ANSWER_TYPES[Number(target.value)].value]: true, }; - updateQuestionsList(quizId, totalIndex, { content: clonContent }); + updateQuestionsList(quizId, totalIndex, { content: clonedContent }); }} > {ANSWER_TYPES.map(({ name }, index) => ( diff --git a/src/pages/Questions/RatingOptions/settingRating.tsx b/src/pages/Questions/RatingOptions/settingRating.tsx index 117bedbb..b9cfd297 100644 --- a/src/pages/Questions/RatingOptions/settingRating.tsx +++ b/src/pages/Questions/RatingOptions/settingRating.tsx @@ -132,7 +132,7 @@ export default function SettingSlider({ totalIndex }: SettingSliderProps) { { updateQuestionsList(quizId, totalIndex, { required: !e.target.checked, diff --git a/src/pages/Questions/SliderOptions/settingSlider.tsx b/src/pages/Questions/SliderOptions/settingSlider.tsx index 014bea27..e98ece76 100644 --- a/src/pages/Questions/SliderOptions/settingSlider.tsx +++ b/src/pages/Questions/SliderOptions/settingSlider.tsx @@ -57,7 +57,7 @@ export default function SettingSlider({ totalIndex }: SettingSliderProps) { { updateQuestionsList(quizId, totalIndex, { required: !e.target.checked, diff --git a/src/pages/Questions/TypeQuestions.tsx b/src/pages/Questions/TypeQuestions.tsx index a87c4ae0..b80affee 100755 --- a/src/pages/Questions/TypeQuestions.tsx +++ b/src/pages/Questions/TypeQuestions.tsx @@ -93,7 +93,6 @@ export const BUTTON_TYPE_QUESTIONS: ButtonTypeQuestion[] = [ export default function TypeQuestions({ totalIndex }: Props) { const quizId = Number(useParams().quizId); const { listQuestions } = questionStore(); - const switchState = listQuestions[quizId][totalIndex].type; return ( { - const clonContent = - listQuestions[quizId][totalIndex].content; - - clonContent.rule.reqs[index] = { - id: String( - STIPULATIONS.findIndex((item) => - item.includes(stipulation) - ) - ), - vars: request.vars, - }; - + + Условие 1 + + { + const clonedContent = { ...question.content }; + clonedContent.rule.reqs.splice(index, 1); updateQuestionsList(quizId, totalIndex, { - content: clonContent, + content: clonedContent, }); }} - sx={{ marginBottom: "15px" }} - /> - {request.id && ( - <> - - - Дан ответ - - - (Укажите один или несколько вариантов) - - - { + const clonedContent = { ...question.content }; + + clonedContent.rule.reqs[index] = { + id: String( + STIPULATIONS.findIndex((item) => + item.includes(stipulation) + ) + ), + vars: request.vars, + }; + + updateQuestionsList(quizId, totalIndex, { + content: clonedContent, + }); + }} + sx={{ marginBottom: "15px" }} + /> + {request.id && ( + <> + + + Дан ответ + + + (Укажите один или несколько вариантов) + + +