ENCOA-228 Now when user navigates between modules the generation items persist. Reading, listening and writing added to level module

This commit is contained in:
Carlos-Mesquita
2024-11-12 14:17:54 +00:00
parent 696c968ebc
commit fdf411d133
66 changed files with 2546 additions and 1635 deletions

View File

@@ -6,9 +6,9 @@ import { reorderSection } from "../reorder/global";
export type SectionActions =
| { type: 'UPDATE_SECTION_SINGLE_FIELD'; payload: { module: Module; sectionId: number; field: string; value: any } }
| { type: 'UPDATE_SECTION_SETTINGS'; payload: { sectionId: number; update: Partial<SectionSettings | ReadingSectionSettings>; } }
| { type: 'UPDATE_SECTION_STATE'; payload: { sectionId: number; update: Partial<Section>; } }
| { type: 'REORDER_EXERCISES'; payload: { event: DragEndEvent, sectionId: number; } };
| { type: 'UPDATE_SECTION_SETTINGS'; payload: { sectionId: number; module: Module; update: Partial<SectionSettings | ReadingSectionSettings>; } }
| { type: 'UPDATE_SECTION_STATE'; payload: { sectionId: number; module: Module; update: Partial<Section>; } }
| { type: 'REORDER_EXERCISES'; payload: { event: DragEndEvent, module: Module; sectionId: number; } };
export const SECTION_ACTIONS = [
'UPDATE_SECTION_SETTINGS',
@@ -20,24 +20,16 @@ export const sectionReducer = (
state: ExamEditorStore,
action: SectionActions
): Partial<ExamEditorStore> => {
const currentModule = state.currentModule;
const modules = state.modules;
const sections = state.modules[currentModule].sections;
let sectionId: number;
if (action.payload && 'sectionId' in action.payload) {
sectionId = action.payload.sectionId;
}
switch (action.type) {
case 'UPDATE_SECTION_SINGLE_FIELD':
const { module, field, value } = action.payload;
case 'UPDATE_SECTION_SINGLE_FIELD':{
const { module, field, value, sectionId } = action.payload;
console.log(`Updating ${module}-${sectionId} ${field} to ${value}`);
return {
modules: {
...modules,
...state.modules,
[module]: {
...modules[module],
sections: sections.map((section: SectionState) =>
...state.modules[module],
sections: state.modules[module].sections.map((section: SectionState) =>
section.sectionId === sectionId
? {
...section,
@@ -48,22 +40,21 @@ export const sectionReducer = (
}
}
};
case 'UPDATE_SECTION_SETTINGS':
let updatedSettings = action.payload.update;
}
case 'UPDATE_SECTION_SETTINGS':{
const {module, sectionId, update} = action.payload;
return {
modules: {
...modules,
[currentModule]: {
...modules[currentModule],
sections: sections.map((section: SectionState) =>
...state.modules,
[module]: {
...state.modules[module],
sections: state.modules[module].sections.map((section: SectionState) =>
section.sectionId === sectionId
? {
...section,
settings: {
...section.settings,
...updatedSettings
...update
}
}
: section
@@ -71,30 +62,32 @@ export const sectionReducer = (
}
}
};
case 'UPDATE_SECTION_STATE':
const updatedState = action.payload.update;
}
case 'UPDATE_SECTION_STATE': {
const { update, module, sectionId }= action.payload;
return {
modules: {
...modules,
[currentModule]: {
...modules[currentModule],
sections: sections.map(section =>
...state.modules,
[module]: {
...state.modules[module],
sections: state.modules[module].sections.map(section =>
section.sectionId === sectionId
? { ...section, state: { ...section.state, ...updatedState } }
? { ...section, state: { ...section.state, ...update } }
: section
)
}
}
};
}
case 'REORDER_EXERCISES': {
const { active, over } = action.payload.event;
const { event, sectionId, module } = action.payload;
const {over, active} = event;
if (!over) return state;
const oldIndex = active.id as number;
const newIndex = over.id as number;
const currentSectionState = sections.find((s) => s.sectionId === sectionId)!.state as ReadingPart | ListeningPart | LevelPart;
const currentSectionState = state.modules[module].sections.find((s) => s.sectionId === sectionId)!.state as ReadingPart | ListeningPart | LevelPart;
const exercises = [...currentSectionState.exercises];
const [removed] = exercises.splice(oldIndex, 1);
exercises.splice(newIndex, 0, removed);
@@ -110,9 +103,9 @@ export const sectionReducer = (
...state,
modules: {
...state.modules,
[currentModule]: {
...modules[currentModule],
sections: sections.map(section =>
[module]: {
...state.modules[module],
sections: state.modules[module].sections.map(section =>
section.sectionId === sectionId
? { ...section, state: newSectionState }
: section