fix: qustions limit

This commit is contained in:
IlyaDoronin 2024-04-19 15:50:05 +03:00
parent 5f93f453f5
commit b0d7bf0305

@ -41,7 +41,17 @@ export const setQuestions = (questions: RawQuestion[] | null | undefined) =>
export const createUntypedQuestion = (
quizId: number,
insertAfterQuestionId?: string,
) =>
) => {
const { questions } = useQuestionsStore.getState();
const questionsAmount = questions.filter(
({ type }) => type !== "result",
).length;
if (questionsAmount >= 100) {
return;
}
setProducedState(
(state) => {
const newUntypedQuestion = {
@ -70,6 +80,7 @@ export const createUntypedQuestion = (
quizId,
},
);
};
const removeQuestion = (questionId: string) =>
setProducedState(
@ -530,8 +541,20 @@ export const deleteQuestion = async (questionId: string) =>
}
});
export const copyQuestion = async (questionId: string, quizId: number) =>
requestQueue.enqueue(`copyQuestion-${quizId}-${questionId}`, async () => {
export const copyQuestion = async (questionId: string, quizId: number) => {
const { questions } = useQuestionsStore.getState();
const questionsAmount = questions.filter(
({ type }) => type !== "result",
).length;
if (questionsAmount >= 100) {
return;
}
return requestQueue.enqueue(
`copyQuestion-${quizId}-${questionId}`,
async () => {
const question = useQuestionsStore
.getState()
.questions.find((q) => q.id === questionId);
@ -589,7 +612,9 @@ export const copyQuestion = async (questionId: string, quizId: number) =>
devlog("Error copying question", error);
enqueueSnackbar("Не удалось скопировать вопрос");
}
});
},
);
};
function setProducedState<A extends string | { type: string }>(
recipe: (state: QuestionsStore) => void,