Exam generation rework, batch user tables, fastapi endpoint switch

This commit is contained in:
Carlos-Mesquita
2024-11-04 23:29:14 +00:00
parent a2bc997e8f
commit 15c9c4d4bd
148 changed files with 11348 additions and 3901 deletions

View File

@@ -1,7 +1,9 @@
import {Module} from "@/interfaces";
import {Exam, ShuffleMap, Shuffles, UserSolution} from "@/interfaces/exam";
import {Assignment} from "@/interfaces/results";
import {create} from "zustand";
import { Module } from "@/interfaces";
import { Exam, Shuffles, UserSolution } from "@/interfaces/exam";
import { Assignment } from "@/interfaces/results";
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";
export interface ExamState {
exams: Exam[];
@@ -67,25 +69,59 @@ export const initialState: ExamState = {
const useExamStore = create<ExamState & ExamFunctions>((set) => ({
...initialState,
setUserSolutions: (userSolutions: UserSolution[]) => set(() => ({userSolutions})),
setExams: (exams: Exam[]) => set(() => ({exams})),
setShowSolutions: (showSolutions: boolean) => set(() => ({showSolutions})),
setSelectedModules: (modules: Module[]) => set(() => ({selectedModules: modules})),
setHasExamEnded: (hasExamEnded: boolean) => set(() => ({hasExamEnded})),
setAssignment: (assignment?: Assignment) => set(() => ({assignment})),
setTimeSpent: (timeSpent) => set(() => ({timeSpent})),
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})),
setQuestionIndex: (questionIndex: number) => set(() => ({questionIndex})),
setInactivity: (inactivity: number) => set(() => ({inactivity})),
setShuffles: (shuffles: Shuffles[]) => set(() => ({shuffles})),
setBgColor: (bgColor) => set(() => ({bgColor})),
setCurrentSolution: (currentSolution: UserSolution | undefined) => set(() => ({currentSolution})),
setUserSolutions: (userSolutions: UserSolution[]) => set(() => ({ userSolutions })),
setExams: (exams: Exam[]) => set(() => ({ exams })),
setShowSolutions: (showSolutions: boolean) => set(() => ({ showSolutions })),
setSelectedModules: (modules: Module[]) => set(() => ({ selectedModules: modules })),
setHasExamEnded: (hasExamEnded: boolean) => set(() => ({ hasExamEnded })),
setAssignment: (assignment?: Assignment) => set(() => ({ assignment })),
setTimeSpent: (timeSpent) => set(() => ({ timeSpent })),
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 })),
setQuestionIndex: (questionIndex: number) => set(() => ({ questionIndex })),
setInactivity: (inactivity: number) => set(() => ({ inactivity })),
setShuffles: (shuffles: Shuffles[]) => set(() => ({ shuffles })),
setBgColor: (bgColor) => set(() => ({ bgColor })),
setCurrentSolution: (currentSolution: UserSolution | undefined) => set(() => ({ currentSolution })),
reset: () => set(() => initialState),
}));
export default useExamStore;
export const usePersistentExamStore = create<ExamState & ExamFunctions>()(
persist(
immer((set) => ({
...initialState,
setUserSolutions: (userSolutions: UserSolution[]) => set(() => ({ userSolutions })),
setExams: (exams: Exam[]) => set(() => ({ exams })),
setShowSolutions: (showSolutions: boolean) => set(() => ({ showSolutions })),
setSelectedModules: (modules: Module[]) => set(() => ({ selectedModules: modules })),
setHasExamEnded: (hasExamEnded: boolean) => set(() => ({ hasExamEnded })),
setAssignment: (assignment?: Assignment) => set(() => ({ assignment })),
setTimeSpent: (timeSpent) => set(() => ({ timeSpent })),
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 })),
setQuestionIndex: (questionIndex: number) => set(() => ({ questionIndex })),
setInactivity: (inactivity: number) => set(() => ({ inactivity })),
setShuffles: (shuffles: Shuffles[]) => set(() => ({ shuffles })),
setBgColor: (bgColor) => set(() => ({ bgColor })),
setCurrentSolution: (currentSolution: UserSolution | undefined) => set(() => ({ currentSolution })),
reset: () => set(() => initialState),
})),
{
name: 'persistent-exam-store',
storage: createJSONStorage(() => localStorage),
partialize: (state) => ({ ...state }),
}
)
);