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