remove questions on quiz delete

This commit is contained in:
nflnkr 2023-10-23 18:33:56 +03:00
parent d4a3025eda
commit 42cf32c185
2 changed files with 8 additions and 1 deletions

@ -121,6 +121,10 @@ export const updateQuestionsList = <T = AnyQuizQuestion>(
questionStore.setState({ listQuestions: questionListClone });
};
export const removeQuestionsByQuizId = (quizId: number) => setProducedState(state => {
delete state.listQuestions[quizId];
}, "removeQuestionsByQuizId");
export const updateQuestionsListDragAndDrop = (
quizId: number,
updatedQuestions: AnyQuizQuestion[]

@ -1,5 +1,6 @@
import {create} from "zustand";
import {persist} from "zustand/middleware";
import { removeQuestionsByQuizId } from "./questions";
interface QuizStore {
listQuizes: { [key: number]: Quizes };
@ -87,6 +88,8 @@ export const quizStore = create<QuizStore>()(
return accumulator;
}, {});
set({listQuizes: newState});
removeQuestionsByQuizId(id);
},
createBlank: () => {
const id = getRandom(1000000, 10000000)
@ -160,4 +163,4 @@ function getRandom(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
}