fix order of created question
This commit is contained in:
parent
e58df2173e
commit
dfe85edc67
@ -387,7 +387,7 @@ console.log(question.type)
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
onClick={() => createUntypedQuestion(question.quizId)}
|
||||
onClick={() => createUntypedQuestion(question.quizId, question.id)}
|
||||
sx={{
|
||||
display: plusVisible && !isDragging ? "flex" : "none",
|
||||
width: "100%",
|
||||
|
@ -26,8 +26,8 @@ export const setQuestions = (questions: RawQuestion[] | null) => setProducedStat
|
||||
questions,
|
||||
});
|
||||
|
||||
export const createUntypedQuestion = (quizId: number) => setProducedState(state => {
|
||||
state.questions.push({
|
||||
export const createUntypedQuestion = (quizId: number, insertAfterQuestionId?: string) => setProducedState(state => {
|
||||
const newUntypedQuestion = {
|
||||
id: nanoid(),
|
||||
quizId,
|
||||
type: null,
|
||||
@ -35,7 +35,16 @@ export const createUntypedQuestion = (quizId: number) => setProducedState(state
|
||||
description: "",
|
||||
deleted: false,
|
||||
expanded: true,
|
||||
});
|
||||
};
|
||||
|
||||
if (insertAfterQuestionId) {
|
||||
const index = state.questions.findIndex(q => q.id === insertAfterQuestionId);
|
||||
if (index === -1) return;
|
||||
state.questions.splice(index + 1, 0, newUntypedQuestion);
|
||||
return;
|
||||
}
|
||||
|
||||
state.questions.push(newUntypedQuestion);
|
||||
}, {
|
||||
type: "createUntypedQuestion",
|
||||
quizId,
|
||||
@ -335,6 +344,8 @@ export const createTypedQuestion = async (
|
||||
type: "createTypedQuestion",
|
||||
question,
|
||||
});
|
||||
|
||||
updateQuestionOrders();
|
||||
} catch (error) {
|
||||
devlog("Error creating question", error);
|
||||
enqueueSnackbar("Не удалось создать вопрос");
|
||||
@ -355,7 +366,7 @@ export const deleteQuestion = async (questionId: string) => requestQueue.enqueue
|
||||
|
||||
try {
|
||||
await questionApi.delete(question.backendId);
|
||||
|
||||
|
||||
removeQuestion(questionId);
|
||||
|
||||
updateQuestionOrders();
|
||||
@ -521,7 +532,7 @@ export const createBackResult = async (
|
||||
rawQuestionToQuestion(createdQuestion)
|
||||
);
|
||||
}, {
|
||||
type: "createTypedQuestion",
|
||||
type: "createBackResult",
|
||||
question,
|
||||
});
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user