42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { create } from "zustand";
|
|
import { devtools } from "zustand/middleware";
|
|
|
|
|
|
interface QuizPreviewStore {
|
|
isPreviewShown: boolean;
|
|
currentQuestionIndex: number;
|
|
}
|
|
|
|
export const useQuizPreviewStore = create<QuizPreviewStore>()(
|
|
devtools(
|
|
(set, get) => ({
|
|
isPreviewShown: false,
|
|
currentQuestionIndex: 0,
|
|
}),
|
|
{
|
|
name: "quizPreview",
|
|
enabled: process.env.NODE_ENV !== "production",
|
|
}
|
|
)
|
|
);
|
|
|
|
export const showQuizPreview = () => useQuizPreviewStore.setState({ isPreviewShown: true });
|
|
|
|
export const hideQuizPreview = () => useQuizPreviewStore.setState({ isPreviewShown: false });
|
|
|
|
export const toggleQuizPreview = () => useQuizPreviewStore.setState(
|
|
state => ({ isPreviewShown: !state.isPreviewShown })
|
|
);
|
|
|
|
export const setCurrentQuestionIndex = (step: number) => useQuizPreviewStore.setState(
|
|
state => ({ currentQuestionIndex:state.currentQuestionIndex = step })
|
|
);
|
|
|
|
export const incrementCurrentQuestionIndex = (maxStep: number) => useQuizPreviewStore.setState(
|
|
state => ({ currentQuestionIndex: Math.min(state.currentQuestionIndex + 1, maxStep) })
|
|
);
|
|
|
|
export const decrementCurrentQuestionIndex = () => useQuizPreviewStore.setState(
|
|
state => ({ currentQuestionIndex: Math.max(state.currentQuestionIndex - 1, 0) })
|
|
);
|