From 6f9be29cd8ac1ee2f35773c529d2c4d7ce95f4bc Mon Sep 17 00:00:00 2001 From: Carlos-Mesquita Date: Mon, 13 Jan 2025 21:02:34 +0000 Subject: [PATCH] ENCOA-312 --- .../ExamEditor/ExercisePicker/ExerciseWizard.tsx | 10 ++++++---- src/components/ExamEditor/ExercisePicker/index.tsx | 2 +- .../SettingsEditor/speaking/components.tsx | 14 ++++++++------ .../SettingsEditor/writing/components.tsx | 10 ++++++---- .../ExamEditor/Standalone/ResetModule.tsx | 4 +++- src/components/ExamEditor/index.tsx | 10 +++++++--- src/pages/api/groups/[id].ts | 1 - src/stores/examEditor/defaults.ts | 4 ++-- src/stores/examEditor/reducers/index.ts | 2 +- 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/components/ExamEditor/ExercisePicker/ExerciseWizard.tsx b/src/components/ExamEditor/ExercisePicker/ExerciseWizard.tsx index 7a3150ef..230017f7 100644 --- a/src/components/ExamEditor/ExercisePicker/ExerciseWizard.tsx +++ b/src/components/ExamEditor/ExercisePicker/ExerciseWizard.tsx @@ -43,12 +43,14 @@ const ExerciseWizard: React.FC = ({ const { difficulty } = useExamEditorStore(state => state.modules[currentModule]); const randomDiff = difficulty.length === 1 - ? capitalize(difficulty[0]) - : `Random (${difficulty.map(dif => capitalize(dif)).join(", ")})` as Difficulty; + ? capitalize(difficulty[0]) + : difficulty.length == 0 ? + "Random" : + `Selected (${difficulty.sort().map(dif => capitalize(dif)).join(", ")})` as Difficulty; const DIFFICULTIES = difficulty.length === 1 - ? ["A1", "A2", "B1", "B2", "C1", "C2"] - : ["A1", "A2", "B1", "B2", "C1", "C2", randomDiff]; + ? ["A1", "A2", "B1", "B2", "C1", "C2", "Random"] + : ["A1", "A2", "B1", "B2", "C1", "C2", randomDiff, "Random"]; useEffect(() => { const initialConfigs = selectedExercises.map(exerciseType => { diff --git a/src/components/ExamEditor/ExercisePicker/index.tsx b/src/components/ExamEditor/ExercisePicker/index.tsx index 06bce493..ff08439a 100644 --- a/src/components/ExamEditor/ExercisePicker/index.tsx +++ b/src/components/ExamEditor/ExercisePicker/index.tsx @@ -69,7 +69,7 @@ const ExercisePicker: React.FC = ({ ...(config.params.max_words !== undefined && { max_words: Number(config.params.max_words) }), - ...(DIFFICULTIES.includes(config.params.difficulty as string) && { + ...((DIFFICULTIES.includes(config.params.difficulty as string) || config.params.difficulty === "Random") && { difficulty: config.params.difficulty }) }; diff --git a/src/components/ExamEditor/SettingsEditor/speaking/components.tsx b/src/components/ExamEditor/SettingsEditor/speaking/components.tsx index d7bc1ffe..5d6668db 100644 --- a/src/components/ExamEditor/SettingsEditor/speaking/components.tsx +++ b/src/components/ExamEditor/SettingsEditor/speaking/components.tsx @@ -41,12 +41,14 @@ const SpeakingComponents: React.FC = ({ localSettings, updateLocalAndSche const [selectedAvatar, setSelectedAvatar] = useState(null); const randomDiff = difficulty.length === 1 - ? capitalize(difficulty[0]) - : `Random (${difficulty.map(dif => capitalize(dif)).join(", ")})` as Difficulty; - - const DIFFICULTIES = difficulty.length === 1 - ? ["A1", "A2", "B1", "B2", "C1", "C2"] - : ["A1", "A2", "B1", "B2", "C1", "C2", randomDiff]; + ? capitalize(difficulty[0]) + : difficulty.length == 0 ? + "Random" : + `Selected (${difficulty.sort().map(dif => capitalize(dif)).join(", ")})` as Difficulty; + + const DIFFICULTIES = difficulty.length === 1 + ? ["A1", "A2", "B1", "B2", "C1", "C2", "Random"] + : ["A1", "A2", "B1", "B2", "C1", "C2", randomDiff, "Random"]; const difficultyOptions: Option[] = DIFFICULTIES.map(level => ({ label: level, diff --git a/src/components/ExamEditor/SettingsEditor/writing/components.tsx b/src/components/ExamEditor/SettingsEditor/writing/components.tsx index 1969993f..927d76b2 100644 --- a/src/components/ExamEditor/SettingsEditor/writing/components.tsx +++ b/src/components/ExamEditor/SettingsEditor/writing/components.tsx @@ -31,12 +31,14 @@ const WritingComponents: React.FC = ({ localSettings, updateLocalAndSched } = useExamEditorStore((store) => store.modules["writing"]); const randomDiff = difficulty.length === 1 - ? capitalize(difficulty[0]) - : `Random (${difficulty.map(dif => capitalize(dif)).join(", ")})` as Difficulty; + ? capitalize(difficulty[0]) + : difficulty.length == 0 ? + "Random" : + `Selected (${difficulty.sort().map(dif => capitalize(dif)).join(", ")})` as Difficulty; const DIFFICULTIES = difficulty.length === 1 - ? ["A1", "A2", "B1", "B2", "C1", "C2"] - : ["A1", "A2", "B1", "B2", "C1", "C2", randomDiff]; + ? ["A1", "A2", "B1", "B2", "C1", "C2", "Random"] + : ["A1", "A2", "B1", "B2", "C1", "C2", randomDiff, "Random"]; const difficultyOptions: Option[] = DIFFICULTIES.map(level => ({ label: level, diff --git a/src/components/ExamEditor/Standalone/ResetModule.tsx b/src/components/ExamEditor/Standalone/ResetModule.tsx index b763f664..d10dbc49 100644 --- a/src/components/ExamEditor/Standalone/ResetModule.tsx +++ b/src/components/ExamEditor/Standalone/ResetModule.tsx @@ -50,7 +50,9 @@ const ResetModule: React.FC = ({ module, isOpen, setIsOpen, setNumberOfLe const handleResetModule = () => { dispatch({ type: 'RESET_MODULE', payload: { module } }); setIsOpen(false); - setNumberOfLevelParts(1); + if (module === "level") { + setNumberOfLevelParts(1); + } } return ( diff --git a/src/components/ExamEditor/index.tsx b/src/components/ExamEditor/index.tsx index 944e2f5a..54e6b87d 100644 --- a/src/components/ExamEditor/index.tsx +++ b/src/components/ExamEditor/index.tsx @@ -216,9 +216,13 @@ const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => { /> {currentModule === "listening" && } - {["reading", "listening", "level"].includes(currentModule) && } +
diff --git a/src/pages/api/groups/[id].ts b/src/pages/api/groups/[id].ts index cdc09c1d..c274d86b 100644 --- a/src/pages/api/groups/[id].ts +++ b/src/pages/api/groups/[id].ts @@ -80,7 +80,6 @@ async function patch(req: NextApiRequest, res: NextApiResponse) { await Promise.all(newParticipants.map(async (p) => await updateExpiryDateOnGroup(p, group.admin))); } - console.log(req.body); await db.collection("groups").updateOne({id}, {$set: {id, ...req.body}}, {upsert: true}); res.status(200).json({ok: true}); diff --git a/src/stores/examEditor/defaults.ts b/src/stores/examEditor/defaults.ts index e07e94aa..972deec5 100644 --- a/src/stores/examEditor/defaults.ts +++ b/src/stores/examEditor/defaults.ts @@ -153,14 +153,14 @@ export const defaultSectionSettings = (module: Module, sectionId: number, part?: } -const defaultModuleSettings = (module: Module, minTimer: number): ModuleState => { +const defaultModuleSettings = (module: Module, minTimer: number, reset: boolean = false): ModuleState => { const state: ModuleState = { examLabel: defaultExamLabel(module), minTimer, difficulty: [sample(["A1", "A2", "B1", "B2", "C1", "C2"] as Difficulty[])!], isPrivate: true, sectionLabels: sectionLabels(module), - expandedSections: [1], + expandedSections: [(reset && (module === "writing" || module === "speaking")) ? 0 : 1], focusedSection: 1, sections: [defaultSectionSettings(module, 1)], importModule: true, diff --git a/src/stores/examEditor/reducers/index.ts b/src/stores/examEditor/reducers/index.ts index 9f7479ae..5ca38647 100644 --- a/src/stores/examEditor/reducers/index.ts +++ b/src/stores/examEditor/reducers/index.ts @@ -59,7 +59,7 @@ export const rootReducer = ( return { modules: { ...state.modules, - [module]: defaultModuleSettings(module, timer), + [module]: defaultModuleSettings(module, timer, true), }, }; case 'FULL_RESET':