- Adapted the exam to store all of its information to Zustand;

- Made it so, every time there is a change or every X seconds, it saves the session;
This commit is contained in:
Tiago Ribeiro
2024-02-06 12:34:45 +00:00
parent 8baa25c445
commit c4b61c4787
13 changed files with 270 additions and 77 deletions

View File

@@ -5,39 +5,36 @@ import {create} from "zustand";
export interface ExamState {
exams: Exam[];
setExams: (exams: Exam[]) => void;
userSolutions: UserSolution[];
setUserSolutions: (userSolutions: UserSolution[]) => void;
showSolutions: boolean;
setShowSolutions: (showSolutions: boolean) => void;
hasExamEnded: boolean;
setHasExamEnded: (hasExamEnded: boolean) => void;
selectedModules: Module[];
setSelectedModules: (modules: Module[]) => void;
assignment?: Assignment;
setAssignment: (assignment: Assignment) => void;
timeSpent: number;
setTimeSpent: (timeSpent: number) => void;
sessionId: string;
setSessionId: (sessionId: string) => void;
moduleIndex: number;
setModuleIndex: (moduleIndex: number) => void;
exam?: Exam;
setExam: (exam?: Exam) => void;
partIndex: number;
exerciseIndex: number;
}
export interface ExamFunctions {
setExams: (exams: Exam[]) => void;
setUserSolutions: (userSolutions: UserSolution[]) => void;
setShowSolutions: (showSolutions: boolean) => void;
setHasExamEnded: (hasExamEnded: boolean) => void;
setSelectedModules: (modules: Module[]) => void;
setAssignment: (assignment: Assignment) => void;
setTimeSpent: (timeSpent: number) => void;
setSessionId: (sessionId: string) => void;
setModuleIndex: (moduleIndex: number) => void;
setExam: (exam?: Exam) => void;
setPartIndex: (partIndex: number) => void;
setExerciseIndex: (exerciseIndex: number) => void;
reset: () => void;
}
export const initialState = {
export const initialState: ExamState = {
exams: [],
userSolutions: [],
showSolutions: false,
@@ -48,9 +45,11 @@ export const initialState = {
sessionId: "",
exam: undefined,
moduleIndex: 0,
partIndex: 0,
exerciseIndex: 0,
};
const useExamStore = create<ExamState>((set) => ({
const useExamStore = create<ExamState & ExamFunctions>((set) => ({
...initialState,
setUserSolutions: (userSolutions: UserSolution[]) => set(() => ({userSolutions})),
@@ -63,6 +62,8 @@ const useExamStore = create<ExamState>((set) => ({
setSessionId: (sessionId: string) => set(() => ({sessionId})),
setExam: (exam?: Exam) => set(() => ({exam})),
setModuleIndex: (moduleIndex: number) => set(() => ({moduleIndex})),
setPartIndex: (partIndex: number) => set(() => ({partIndex})),
setExerciseIndex: (exerciseIndex: number) => set(() => ({exerciseIndex})),
reset: () => set(() => initialState),
}));