remove blob urls on persisted state
This commit is contained in:
parent
db8e8029d0
commit
1c8b2aef2f
@ -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<string, AnyQuizQuestion[]>;
|
||||
@ -59,6 +63,37 @@ export const questionStore = create<QuestionStore>()(
|
||||
|
||||
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,
|
||||
};
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user