2023-10-03 16:05:20 +00:00
|
|
|
import { create } from "zustand";
|
|
|
|
import { devtools } from "zustand/middleware";
|
|
|
|
|
|
|
|
|
|
|
|
interface QuizPreviewStore {
|
|
|
|
isPreviewShown: boolean;
|
2023-10-09 12:33:45 +00:00
|
|
|
currentQuestionIndex: number;
|
2023-10-03 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const useQuizPreviewStore = create<QuizPreviewStore>()(
|
|
|
|
devtools(
|
|
|
|
(set, get) => ({
|
2023-11-03 13:10:04 +00:00
|
|
|
isPreviewShown: false,
|
2023-10-09 12:33:45 +00:00
|
|
|
currentQuestionIndex: 0,
|
2023-10-03 16:05:20 +00:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
name: "quizPreview",
|
|
|
|
enabled: process.env.NODE_ENV !== "production",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
export const showQuizPreview = () => useQuizPreviewStore.setState({ isPreviewShown: true });
|
|
|
|
|
|
|
|
export const hideQuizPreview = () => useQuizPreviewStore.setState({ isPreviewShown: false });
|
|
|
|
|
2023-10-05 11:41:54 +00:00
|
|
|
export const toggleQuizPreview = () => useQuizPreviewStore.setState(
|
|
|
|
state => ({ isPreviewShown: !state.isPreviewShown })
|
|
|
|
);
|
2023-10-03 16:05:20 +00:00
|
|
|
|
2023-11-30 06:27:15 +00:00
|
|
|
export const setCurrentQuestionIndex = (step: number) => useQuizPreviewStore.setState(
|
|
|
|
state => ({ currentQuestionIndex:state.currentQuestionIndex = step })
|
|
|
|
);
|
|
|
|
|
2023-10-09 12:33:45 +00:00
|
|
|
export const incrementCurrentQuestionIndex = (maxStep: number) => useQuizPreviewStore.setState(
|
|
|
|
state => ({ currentQuestionIndex: Math.min(state.currentQuestionIndex + 1, maxStep) })
|
2023-10-05 11:41:54 +00:00
|
|
|
);
|
2023-10-03 16:05:20 +00:00
|
|
|
|
2023-10-09 12:33:45 +00:00
|
|
|
export const decrementCurrentQuestionIndex = () => useQuizPreviewStore.setState(
|
|
|
|
state => ({ currentQuestionIndex: Math.max(state.currentQuestionIndex - 1, 0) })
|
2023-10-05 11:41:54 +00:00
|
|
|
);
|