From a2a513077f7b9c84a6718652700f89ea2e3d925f Mon Sep 17 00:00:00 2001 From: Carlos-Mesquita Date: Wed, 27 Nov 2024 02:01:50 +0000 Subject: [PATCH] Exam Edit on ExamList --- .../Exercises/Shared/PromptEdit.tsx | 9 +-- .../ExamEditor/SettingsEditor/index.tsx | 1 - src/components/ExamEditor/index.tsx | 34 ++++++--- src/components/Low/AutoExpandingTextarea.tsx | 6 +- src/exams/Level/index.tsx | 19 +++-- src/exams/Listening.tsx | 2 + src/exams/Navigation/SectionDivider.tsx | 17 ++++- src/exams/utils/answeredEveryQuestion.ts | 1 - src/pages/(admin)/Lists/ExamList.tsx | 53 ++++++++++++-- src/pages/(exam)/ExamPage.tsx | 1 - src/pages/generation.tsx | 35 ++++++---- src/stores/examEditor/defaults.ts | 5 +- src/stores/examEditor/reducers/index.ts | 69 +++++++++++++++++-- 13 files changed, 199 insertions(+), 53 deletions(-) diff --git a/src/components/ExamEditor/Exercises/Shared/PromptEdit.tsx b/src/components/ExamEditor/Exercises/Shared/PromptEdit.tsx index 760dd749..11ae5f79 100644 --- a/src/components/ExamEditor/Exercises/Shared/PromptEdit.tsx +++ b/src/components/ExamEditor/Exercises/Shared/PromptEdit.tsx @@ -22,18 +22,13 @@ const PromptEdit: React.FC = ({ value, onChange, wrapperCard = true }) => )); }; - const handleTextChange = (text: string) => { - const escapedText = text.replace(/\n/g, '\\n'); - onChange(escapedText); - }; - const promptEditTsx = (
{editing ? ( setEditing(false)} /> ) : ( diff --git a/src/components/ExamEditor/SettingsEditor/index.tsx b/src/components/ExamEditor/SettingsEditor/index.tsx index c996482d..afb2bccb 100644 --- a/src/components/ExamEditor/SettingsEditor/index.tsx +++ b/src/components/ExamEditor/SettingsEditor/index.tsx @@ -79,7 +79,6 @@ const SettingsEditor: React.FC = ({ currentIntro: text }); }, [updateLocalAndScheduleGlobal]); - return (
diff --git a/src/components/ExamEditor/index.tsx b/src/components/ExamEditor/index.tsx index 36acd08c..db6b2c47 100644 --- a/src/components/ExamEditor/index.tsx +++ b/src/components/ExamEditor/index.tsx @@ -20,7 +20,7 @@ import { defaultSectionSettings } from "@/stores/examEditor/defaults"; const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"]; -const ExamEditor: React.FC = () => { +const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => { const { currentModule, dispatch } = useExamEditorStore(); const { sections, @@ -33,18 +33,34 @@ const ExamEditor: React.FC = () => { importModule } = useExamEditorStore(state => state.modules[currentModule]); - const [numberOfLevelParts, setNumberOfLevelParts] = useState(1); + const [numberOfLevelParts, setNumberOfLevelParts] = useState(levelParts !== undefined ? levelParts : 1); + + useEffect(() => { + setNumberOfLevelParts(levelParts); + dispatch({ + type: 'UPDATE_MODULE', + payload: { + updates: { + sectionLabels: Array.from({ length: levelParts }).map((_, i) => ({ + id: i + 1, + label: `Part ${i + 1}` + })) + } + } + }) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [levelParts]) useEffect(() => { const currentSections = sections; const currentLabels = sectionLabels; let updatedSections: SectionState[]; let updatedLabels: any; - + if (numberOfLevelParts > currentSections.length) { const newSections = [...currentSections]; const newLabels = [...currentLabels]; - + for (let i = currentSections.length; i < numberOfLevelParts; i++) { newSections.push(defaultSectionSettings(currentModule, i + 1)); newLabels.push({ @@ -60,11 +76,11 @@ const ExamEditor: React.FC = () => { } else { return; } - + const updatedExpandedSections = expandedSections.filter( sectionId => updatedSections.some(section => section.sectionId === sectionId) ); - + dispatch({ type: 'UPDATE_MODULE', payload: { @@ -75,7 +91,7 @@ const ExamEditor: React.FC = () => { } } }); - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [numberOfLevelParts]); @@ -103,10 +119,10 @@ const ExamEditor: React.FC = () => { const Settings = ModuleSettings[currentModule]; const showImport = importModule && ["reading", "listening", "level"].includes(currentModule); - + return ( <> - {showImport ? : ( + {showImport ? : ( <>
diff --git a/src/components/Low/AutoExpandingTextarea.tsx b/src/components/Low/AutoExpandingTextarea.tsx index 39877246..78c9d6cd 100755 --- a/src/components/Low/AutoExpandingTextarea.tsx +++ b/src/components/Low/AutoExpandingTextarea.tsx @@ -1,11 +1,11 @@ -import React, { useEffect, useRef, ChangeEvent } from 'react'; +import React, { useRef, useEffect, ChangeEvent } from 'react'; interface Props { value: string; - onChange: (value: string) => void; className?: string; placeholder?: string; disabled?: boolean; + onChange: (value: string) => void; onBlur?: () => void; } @@ -41,7 +41,7 @@ const AutoExpandingTextArea: React.FC = ({ return (