Exam generation rework, batch user tables, fastapi endpoint switch
This commit is contained in:
49
src/stores/examEditor/reducers/index.ts
Normal file
49
src/stores/examEditor/reducers/index.ts
Normal 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 {};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user