fix questions store type errors
This commit is contained in:
parent
525977609d
commit
30e9dec88b
@ -123,7 +123,7 @@ export const updateQuestion = (
|
|||||||
updateFn: (question: AnyTypedQuizQuestion) => void,
|
updateFn: (question: AnyTypedQuizQuestion) => void,
|
||||||
) => {
|
) => {
|
||||||
setProducedState(state => {
|
setProducedState(state => {
|
||||||
const question = state.questions.find(q => q.id === questionId) || state.questions.find(q => q.content.id === questionId);
|
const question = state.questions.find(q => q.id === questionId) || state.questions.find(q => q.type !== null && q.content.id === questionId);
|
||||||
if (!question) return;
|
if (!question) return;
|
||||||
if (question.type === null) throw new Error("Cannot update untyped question, use 'updateUntypedQuestion' instead");
|
if (question.type === null) throw new Error("Cannot update untyped question, use 'updateUntypedQuestion' instead");
|
||||||
|
|
||||||
@ -137,11 +137,11 @@ export const updateQuestion = (
|
|||||||
// clearTimeout(requestTimeoutId);
|
// clearTimeout(requestTimeoutId);
|
||||||
// requestTimeoutId = setTimeout(() => {
|
// requestTimeoutId = setTimeout(() => {
|
||||||
requestQueue.enqueue(async () => {
|
requestQueue.enqueue(async () => {
|
||||||
const q = useQuestionsStore.getState().questions.find(q => q.id === questionId) || useQuestionsStore.getState().questions.find(q => q.content.id === questionId);
|
const q = useQuestionsStore.getState().questions.find(q => q.id === questionId) || useQuestionsStore.getState().questions.find(q => q.type !== null && q.content.id === questionId);
|
||||||
console.log("мы пытаемся найти вопрос ")
|
console.log("мы пытаемся найти вопрос ");
|
||||||
if (!q) return;
|
if (!q) return;
|
||||||
if (q.type === null) throw new Error("Cannot send update request for untyped question");
|
if (q.type === null) throw new Error("Cannot send update request for untyped question");
|
||||||
console.log(q.title)
|
console.log(q.title);
|
||||||
|
|
||||||
const response = await questionApi.edit(questionToEditQuestionRequest(q));
|
const response = await questionApi.edit(questionToEditQuestionRequest(q));
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ function setProducedState<A extends string | { type: unknown; }>(
|
|||||||
|
|
||||||
|
|
||||||
export const cleardragQuestionContentId = () => {
|
export const cleardragQuestionContentId = () => {
|
||||||
useQuestionsStore.setState({dragQuestionContentId: null});
|
useQuestionsStore.setState({ dragQuestionContentId: null });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getQuestionById = (questionId: string | null) => {
|
export const getQuestionById = (questionId: string | null) => {
|
||||||
@ -377,16 +377,19 @@ export const getQuestionById = (questionId: string | null) => {
|
|||||||
return useQuestionsStore.getState().questions.find(q => q.id === questionId) || null;
|
return useQuestionsStore.getState().questions.find(q => q.id === questionId) || null;
|
||||||
};
|
};
|
||||||
export const getQuestionByContentId = (questionContentId: string | null) => {
|
export const getQuestionByContentId = (questionContentId: string | null) => {
|
||||||
console.log("questionContentId " + questionContentId)
|
console.log("questionContentId " + questionContentId);
|
||||||
if (questionContentId === null) return null;
|
if (questionContentId === null) return null;
|
||||||
return useQuestionsStore.getState().questions.find(q => {
|
return useQuestionsStore.getState().questions.find(q => {
|
||||||
console.log(q.content.id)
|
if (q.type === null) return false;
|
||||||
console.log(q.content.id === questionContentId)
|
|
||||||
return ( q.content.id === questionContentId)}) || null;
|
console.log(q.content.id);
|
||||||
|
console.log(q.content.id === questionContentId);
|
||||||
|
return (q.content.id === questionContentId);
|
||||||
|
}) || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateOpenedModalSettingsId = (id?: string) => useQuestionsStore.setState({openedModalSettingsId: id ? id : null});
|
export const updateOpenedModalSettingsId = (id?: string) => useQuestionsStore.setState({ openedModalSettingsId: id ? id : null });
|
||||||
export const updateDragQuestionContentId = (contentId?: string) => {
|
export const updateDragQuestionContentId = (contentId?: string) => {
|
||||||
console.log("contentId " + contentId)
|
console.log("contentId " + contentId);
|
||||||
useQuestionsStore.setState({dragQuestionContentId: contentId ? contentId : null});
|
useQuestionsStore.setState({ dragQuestionContentId: contentId ? contentId : null });
|
||||||
}
|
};
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { devtools } from "zustand/middleware";
|
|||||||
|
|
||||||
|
|
||||||
export type QuestionsStore = {
|
export type QuestionsStore = {
|
||||||
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion);
|
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion)[];
|
||||||
openedModalSettingsId: string | null;
|
openedModalSettingsId: string | null;
|
||||||
dragQuestionContentId: string | null;
|
dragQuestionContentId: string | null;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user