Revamped the whole Solutions stuff with Zustand

This commit is contained in:
Tiago Ribeiro
2023-05-17 17:33:53 +01:00
parent 44ad687bcf
commit f337540629
4 changed files with 83 additions and 13 deletions

View File

@@ -1,25 +1,28 @@
import {Module} from "@/interfaces";
import {Exam} from "@/interfaces/exam";
import {Exam, UserSolution} from "@/interfaces/exam";
import {Stat} from "@/interfaces/user";
import {getExamsBySession} from "@/utils/stats";
import {create} from "zustand";
export interface ExamState {
exams: Exam[];
stats: Stat[];
userSolutions: UserSolution[];
showSolutions: boolean;
setStats: (stats: Stat[]) => void;
selectedModules: Module[];
setUserSolutions: (userSolutions: UserSolution[]) => void;
setExams: (exams: Exam[]) => void;
setShowSolutions: (showSolutions: boolean) => void;
setSelectedModules: (modules: Module[]) => void;
}
const useExamStore = create<ExamState>((set) => ({
exams: [],
stats: [],
userSolutions: [],
showSolutions: false,
setStats: (stats: Stat[]) => set(() => ({stats})),
selectedModules: [],
setUserSolutions: (userSolutions: UserSolution[]) => set(() => ({userSolutions})),
setExams: (exams: Exam[]) => set(() => ({exams})),
setShowSolutions: (showSolutions: boolean) => set(() => ({showSolutions})),
setSelectedModules: (modules: Module[]) => set(() => ({selectedModules: modules})),
}));
export default useExamStore;