Merged in feature/ExamGenRework (pull request #121)
ENCOA-255 Fixed the level import Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -8,7 +8,7 @@ import useExamEditorStore from '@/stores/examEditor';
|
||||
|
||||
const ImportOrFromScratch: React.FC<{
|
||||
module: Module;
|
||||
setNumberOfLevelParts: React.Dispatch<React.SetStateAction<number>>
|
||||
setNumberOfLevelParts: (parts: number) => void;
|
||||
}> = ({ module, setNumberOfLevelParts }) => {
|
||||
const { currentModule, dispatch } = useExamEditorStore();
|
||||
const { importing } = useExamEditorStore((store) => store.modules[currentModule])
|
||||
|
||||
@@ -9,9 +9,8 @@ import useExamEditorStore from '@/stores/examEditor';
|
||||
import { LevelPart, ListeningPart, ReadingPart } from '@/interfaces/exam';
|
||||
import { defaultSectionSettings } from '@/stores/examEditor/defaults';
|
||||
|
||||
const WordUploader: React.FC<{ module: Module, setNumberOfLevelParts: React.Dispatch<React.SetStateAction<number>> }> = ({ module, setNumberOfLevelParts }) => {
|
||||
const WordUploader: React.FC<{ module: Module, setNumberOfLevelParts: (parts: number) => void; }> = ({ module, setNumberOfLevelParts }) => {
|
||||
const { currentModule, dispatch } = useExamEditorStore();
|
||||
const {sectionLabels} = useExamEditorStore(state => state.modules[currentModule]);
|
||||
|
||||
const examInputRef = useRef<HTMLInputElement>(null);
|
||||
const solutionsInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -77,16 +76,7 @@ const WordUploader: React.FC<{ module: Module, setNumberOfLevelParts: React.Disp
|
||||
);
|
||||
|
||||
if (module === "level") {
|
||||
// default is 1
|
||||
const newLabelCount = data.parts.length - 2;
|
||||
setNumberOfLevelParts(newLabelCount);
|
||||
|
||||
const newLabels = Array.from({ length: newLabelCount }, (_, index) => ({
|
||||
id: index + 2,
|
||||
label: `Part ${index + 2}`
|
||||
}));
|
||||
|
||||
dispatch({type: "UPDATE_MODULE", payload: { updates: { sectionLabels: [...sectionLabels, ...newLabels] }}})
|
||||
setNumberOfLevelParts(data.parts.length);
|
||||
}
|
||||
|
||||
dispatch({
|
||||
|
||||
@@ -10,20 +10,28 @@ interface Props {
|
||||
|
||||
const LevelContext: React.FC<Props> = ({ sectionId }) => {
|
||||
const { currentModule } = useExamEditorStore();
|
||||
const { generating, readingSection, listeningSection } = useExamEditorStore(
|
||||
const { generating, readingSection, listeningSection, state } = useExamEditorStore(
|
||||
(state) => state.modules[currentModule].sections.find((section) => section.sectionId === sectionId)!
|
||||
);
|
||||
|
||||
const hasReadingContext =
|
||||
'text' in state &&
|
||||
state.text !== undefined &&
|
||||
typeof state.text === 'object' &&
|
||||
'content' in state.text &&
|
||||
state.text.content !== undefined &&
|
||||
state.text.content !== "";
|
||||
|
||||
return (
|
||||
<>
|
||||
{generating && (
|
||||
(generating === "passage" && <GenLoader module="reading" />) ||
|
||||
(generating === "listeningScript" && <GenLoader module="listening" />)
|
||||
)}
|
||||
{(readingSection || listeningSection) && (
|
||||
{(readingSection || listeningSection || hasReadingContext) && (
|
||||
<div className="space-y-4 mb-4">
|
||||
{readingSection && <ReadingContext sectionId={sectionId} module="level" />}
|
||||
{listeningSection && <ListeningContext sectionId={sectionId} listeningSection={listeningSection} module="level" level={true}/>}
|
||||
{readingSection || hasReadingContext && <ReadingContext sectionId={sectionId} module="level" />}
|
||||
{listeningSection && <ListeningContext sectionId={sectionId} listeningSection={listeningSection} module="level" level={true} />}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -35,6 +35,7 @@ const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => {
|
||||
|
||||
const [numberOfLevelParts, setNumberOfLevelParts] = useState(levelParts !== 0 ? levelParts : 1);
|
||||
|
||||
// For exam edits
|
||||
useEffect(() => {
|
||||
if (levelParts !== 0) {
|
||||
setNumberOfLevelParts(levelParts);
|
||||
@@ -59,13 +60,11 @@ const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => {
|
||||
const currentLabels = sectionLabels;
|
||||
let updatedSections: SectionState[];
|
||||
let updatedLabels: any;
|
||||
|
||||
if (numberOfLevelParts > currentSections.length) {
|
||||
if (currentModule === "level" && currentSections.length !== currentLabels.length || numberOfLevelParts !== currentSections.length) {
|
||||
const newSections = [...currentSections];
|
||||
const newLabels = [...currentLabels];
|
||||
|
||||
for (let i = currentSections.length; i < numberOfLevelParts; i++) {
|
||||
newSections.push(defaultSectionSettings(currentModule, i + 1));
|
||||
for (let i = currentLabels.length; i < numberOfLevelParts; i++) {
|
||||
if (currentSections.length !== numberOfLevelParts) newSections.push(defaultSectionSettings(currentModule, i + 1));
|
||||
newLabels.push({
|
||||
id: i + 1,
|
||||
label: `Part ${i + 1}`
|
||||
@@ -97,7 +96,6 @@ const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [numberOfLevelParts]);
|
||||
|
||||
|
||||
const sectionIds = sections.map((section) => section.sectionId)
|
||||
|
||||
const updateModule = useCallback((updates: Partial<ModuleState>) => {
|
||||
@@ -123,9 +121,13 @@ const ExamEditor: React.FC<{ levelParts?: number }> = ({ levelParts = 0 }) => {
|
||||
const Settings = ModuleSettings[currentModule];
|
||||
const showImport = importModule && ["reading", "listening", "level"].includes(currentModule);
|
||||
|
||||
const updateLevelParts = (parts: number) => {
|
||||
setNumberOfLevelParts(parts);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{showImport ? <ImportOrStartFromScratch module={currentModule} setNumberOfLevelParts={setNumberOfLevelParts} /> : (
|
||||
{showImport ? <ImportOrStartFromScratch module={currentModule} setNumberOfLevelParts={updateLevelParts} /> : (
|
||||
<>
|
||||
<div className="flex gap-4 w-full items-center">
|
||||
<div className="flex flex-col gap-3">
|
||||
|
||||
@@ -94,7 +94,13 @@ export const sectionLabels = (module: Module, levelParts?: number) => {
|
||||
label: `Section ${index + 1}`
|
||||
}));
|
||||
case 'level':
|
||||
return [{ id: 1, label: "Part 1" }];
|
||||
return levelParts !== undefined ?
|
||||
Array.from({ length: levelParts }, (_, index) => ({
|
||||
id: index + 1,
|
||||
label: `Part ${index + 1}`
|
||||
}))
|
||||
:
|
||||
[{ id: 1, label: "Part 1" }];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user