remove questions on quiz delete
This commit is contained in:
parent
d4a3025eda
commit
42cf32c185
@ -121,6 +121,10 @@ export const updateQuestionsList = <T = AnyQuizQuestion>(
|
|||||||
questionStore.setState({ listQuestions: questionListClone });
|
questionStore.setState({ listQuestions: questionListClone });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const removeQuestionsByQuizId = (quizId: number) => setProducedState(state => {
|
||||||
|
delete state.listQuestions[quizId];
|
||||||
|
}, "removeQuestionsByQuizId");
|
||||||
|
|
||||||
export const updateQuestionsListDragAndDrop = (
|
export const updateQuestionsListDragAndDrop = (
|
||||||
quizId: number,
|
quizId: number,
|
||||||
updatedQuestions: AnyQuizQuestion[]
|
updatedQuestions: AnyQuizQuestion[]
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {create} from "zustand";
|
import {create} from "zustand";
|
||||||
import {persist} from "zustand/middleware";
|
import {persist} from "zustand/middleware";
|
||||||
|
import { removeQuestionsByQuizId } from "./questions";
|
||||||
|
|
||||||
interface QuizStore {
|
interface QuizStore {
|
||||||
listQuizes: { [key: number]: Quizes };
|
listQuizes: { [key: number]: Quizes };
|
||||||
@ -87,6 +88,8 @@ export const quizStore = create<QuizStore>()(
|
|||||||
return accumulator;
|
return accumulator;
|
||||||
}, {});
|
}, {});
|
||||||
set({listQuizes: newState});
|
set({listQuizes: newState});
|
||||||
|
|
||||||
|
removeQuestionsByQuizId(id);
|
||||||
},
|
},
|
||||||
createBlank: () => {
|
createBlank: () => {
|
||||||
const id = getRandom(1000000, 10000000)
|
const id = getRandom(1000000, 10000000)
|
||||||
@ -160,4 +163,4 @@ function getRandom(min: number, max: number) {
|
|||||||
min = Math.ceil(min);
|
min = Math.ceil(min);
|
||||||
max = Math.floor(max);
|
max = Math.floor(max);
|
||||||
return Math.floor(Math.random() * (max - min)) + min;
|
return Math.floor(Math.random() * (max - min)) + min;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user