diff --git a/src/stores/questions.ts b/src/stores/questions.ts index c5b3ebea..26d0f611 100644 --- a/src/stores/questions.ts +++ b/src/stores/questions.ts @@ -24,6 +24,10 @@ import { QUIZ_QUESTION_SELECT } from "../constants/select"; import { QUIZ_QUESTION_TEXT } from "../constants/text"; import { QUIZ_QUESTION_VARIANT } from "../constants/variant"; import { QUIZ_QUESTION_VARIMG } from "../constants/varimg"; +import { setAutoFreeze } from "immer"; + + +setAutoFreeze(false); interface QuestionStore { listQuestions: Record; @@ -59,6 +63,37 @@ export const questionStore = create()( return state; }, + 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 = ""; + } + }); + } + }); + }); + + return { + ...currentState, + ...state, + }; + }, } ) );