diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index 078c96e6..9c2488d7 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -49,7 +49,10 @@ import { ArrowDownIcon } from "@icons/questionsPage/ArrowDownIcon"; import { ReactComponent as PlusIcon } from "../../../assets/icons/plus.svg"; import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd"; -import type { AnyQuizQuestion, QuizQuestionInitial } from "../../../model/questionTypes/shared"; +import type { + AnyQuizQuestion, + QuizQuestionInitial, +} from "../../../model/questionTypes/shared"; interface Props { totalIndex: number; diff --git a/src/stores/questions.ts b/src/stores/questions.ts index 64cf258d..55bf985c 100644 --- a/src/stores/questions.ts +++ b/src/stores/questions.ts @@ -26,7 +26,6 @@ import { QUIZ_QUESTION_VARIANT } from "../constants/variant"; import { QUIZ_QUESTION_VARIMG } from "../constants/varimg"; import { setAutoFreeze } from "immer"; - setAutoFreeze(false); interface QuestionStore { @@ -63,37 +62,40 @@ export const questionStore = create()( return state; }, - merge: (persistedState, currentState) => { - const state = persistedState as QuestionStore; + merge: (persistedState, currentState) => { + const state = persistedState as QuestionStore; - // replace blob urls with "" - Object.values(state.listQuestions).forEach(questions => { - questions.forEach(question => { - if (question.type === "page" && question.content.picture.startsWith("blob:")) { - question.content.picture = ""; - } - if (question.type === "images") { - question.content.variants.forEach(variant => { - if (variant.extendedText.startsWith("blob:")) { - variant.extendedText = ""; - } - }); - } - if (question.type === "varimg") { - question.content.variants.forEach(variant => { - if (variant.extendedText.startsWith("blob:")) { - variant.extendedText = ""; - } - }); - } - }); - }); + // replace blob urls with "" + Object.values(state.listQuestions).forEach((questions) => { + questions.forEach((question) => { + if ( + question.type === "page" && + question.content.picture.startsWith("blob:") + ) { + question.content.picture = ""; + } + if (question.type === "images") { + question.content.variants.forEach((variant) => { + if (variant.extendedText.startsWith("blob:")) { + variant.extendedText = ""; + } + }); + } + if (question.type === "varimg") { + question.content.variants.forEach((variant) => { + if (variant.extendedText.startsWith("blob:")) { + variant.extendedText = ""; + } + }); + } + }); + }); - return { - ...currentState, - ...state, - }; - }, + return { + ...currentState, + ...state, + }; + }, } ) ); @@ -191,13 +193,11 @@ export const createQuestion = ( export const copyQuestion = (quizId: number, copiedQuestionIndex: number) => { const listQuestions = { ...questionStore.getState()["listQuestions"] }; - const copiedQuiz = listQuestions[quizId][copiedQuestionIndex] - copiedQuiz.id = getRandom() - listQuestions[quizId].splice( - copiedQuestionIndex, - 0, - copiedQuiz - ); + const copiedQuiz = { ...listQuestions[quizId][copiedQuestionIndex] }; + listQuestions[quizId].splice(copiedQuestionIndex, 0, { + ...copiedQuiz, + id: getRandom(), + }); questionStore.setState({ listQuestions }); }; @@ -238,4 +238,4 @@ function getRandom() { const min = Math.ceil(1000000); const max = Math.floor(10000000); return Math.floor(Math.random() * (max - min)) + min; -} \ No newline at end of file +}