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