fix: removing question bug
This commit is contained in:
parent
833b87319f
commit
ba620de334
@ -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;
|
||||
|
@ -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<QuestionStore>()(
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user