ENCOA-311
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
||||
import SortableSection from "../../Shared/SortableSection";
|
||||
import { Exercise, InteractiveSpeakingExercise, LevelPart, ListeningPart, ReadingPart, SpeakingExercise, WritingExercise } from "@/interfaces/exam";
|
||||
import { Difficulty, Exercise, InteractiveSpeakingExercise, LevelPart, ListeningPart, ReadingPart, SpeakingExercise, WritingExercise } from "@/interfaces/exam";
|
||||
import ExerciseItem from "./types";
|
||||
import Dropdown from "@/components/Dropdown";
|
||||
import useExamEditorStore from "@/stores/examEditor";
|
||||
@@ -32,8 +32,7 @@ const SectionExercises: React.FC<{ sectionId: number; }> = ({ sectionId }) => {
|
||||
const dispatch = useExamEditorStore(state => state.dispatch);
|
||||
const currentModule = useExamEditorStore(state => state.currentModule);
|
||||
|
||||
const sections = useExamEditorStore(state => state.modules[currentModule].sections);
|
||||
const expandedSections = useExamEditorStore(state => state.modules[currentModule].expandedSections);
|
||||
const {sections, expandedSections, difficulty} = useExamEditorStore(state => state.modules[currentModule]);
|
||||
|
||||
const section = useExamEditorStore(
|
||||
state => state.modules[currentModule].sections.find(
|
||||
@@ -50,6 +49,15 @@ const SectionExercises: React.FC<{ sectionId: number; }> = ({ sectionId }) => {
|
||||
useEffect(() => {
|
||||
if (genResult && genResult.generating === "exercises" && genResult.module === currentModule) {
|
||||
const newExercises = genResult.result[0].exercises;
|
||||
|
||||
const newDifficulties = newExercises
|
||||
.map((ex: Exercise) => ex.difficulty)
|
||||
.filter((diff: Difficulty) => !difficulty.includes(diff));
|
||||
|
||||
if (newDifficulties.length > 0) {
|
||||
dispatch({ type: 'UPDATE_MODULE', payload: { updates: { difficulty: [...difficulty, ...newDifficulties]} } });
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "UPDATE_SECTION_STATE", payload: {
|
||||
sectionId,
|
||||
@@ -85,6 +93,18 @@ const SectionExercises: React.FC<{ sectionId: number; }> = ({ sectionId }) => {
|
||||
) => {
|
||||
const nonWritingOrSpeaking = results[0]?.generating.startsWith("exercises");
|
||||
|
||||
const newExercises = assignExercisesFn(results);
|
||||
|
||||
const newDifficulties = newExercises
|
||||
.map((ex: Exercise) => ex.difficulty)
|
||||
.filter((diff: Difficulty | undefined): diff is Difficulty =>
|
||||
diff !== undefined && !difficulty.includes(diff)
|
||||
);
|
||||
|
||||
if (newDifficulties.length > 0) {
|
||||
dispatch({ type: 'UPDATE_MODULE', payload: { updates: { difficulty: [...difficulty, ...newDifficulties]} } });
|
||||
}
|
||||
|
||||
const updates = [
|
||||
{
|
||||
type: "UPDATE_SECTION_STATE",
|
||||
@@ -94,7 +114,7 @@ const SectionExercises: React.FC<{ sectionId: number; }> = ({ sectionId }) => {
|
||||
update: {
|
||||
exercises: [
|
||||
...sectionState.exercises,
|
||||
...assignExercisesFn(results)
|
||||
...newExercises
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -168,6 +188,7 @@ const SectionExercises: React.FC<{ sectionId: number; }> = ({ sectionId }) => {
|
||||
results.map(res => ({
|
||||
...writingTask(res.generating === "writing_letter" ? 1 : 2),
|
||||
prompt: res.result[0].prompt,
|
||||
difficulty: res.result[0].difficulty,
|
||||
variant: res.generating === "writing_letter" ? "letter" : "essay"
|
||||
}) as WritingExercise);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ const getSpeakingTaskData = (taskNumber: number, data: any) => {
|
||||
video_url: ""
|
||||
}))
|
||||
],
|
||||
difficulty: data.difficulty,
|
||||
sectionId: 1,
|
||||
};
|
||||
case 2:
|
||||
@@ -29,6 +30,7 @@ const getSpeakingTaskData = (taskNumber: number, data: any) => {
|
||||
title: data.topic,
|
||||
text: data.question,
|
||||
prompts: data.prompts,
|
||||
difficulty: data.difficulty,
|
||||
sectionId: 2,
|
||||
type: "speaking"
|
||||
};
|
||||
@@ -39,6 +41,7 @@ const getSpeakingTaskData = (taskNumber: number, data: any) => {
|
||||
text: item || "",
|
||||
video_url: ""
|
||||
})),
|
||||
difficulty: data.difficulty,
|
||||
sectionId: 3,
|
||||
};
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user