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