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

@@ -0,0 +1,49 @@
import ExamEditorStore from "../types";
import { MODULE_ACTIONS, ModuleActions, moduleReducer } from "./moduleReducer";
import { SECTION_ACTIONS, SectionActions, sectionReducer } from "./sectionReducer";
export type Action = ModuleActions | SectionActions | { type: 'UPDATE_ROOT'; payload: { updates: Partial<ExamEditorStore> } };
export const rootReducer = (
state: ExamEditorStore,
action: Action
): Partial<ExamEditorStore> => {
if (MODULE_ACTIONS.includes(action.type as any)) {
if (action.type === "REORDER_EXERCISES" && "payload" in action && "event" in action.payload) {
const updatedState = sectionReducer(state, action as SectionActions);
if (!updatedState.modules) return state;
return moduleReducer({
...state,
modules: updatedState.modules
}, { type: "REORDER_EXERCISES" });
}
return moduleReducer(state, action as ModuleActions);
}
if (SECTION_ACTIONS.includes(action.type as any)) {
if (action.type === "UPDATE_SECTION_STATE") {
const updatedState = sectionReducer(state, action as SectionActions);
if (!updatedState.modules) return state;
return moduleReducer({
...state,
modules: updatedState.modules
}, { type: "REORDER_EXERCISES" });
}
return sectionReducer(state, action as SectionActions);
}
switch (action.type) {
case 'UPDATE_ROOT':
const { updates } = action.payload;
return {
...state,
...updates
};
default:
return {};
}
};