ENCOA-311
This commit is contained in:
@@ -8,6 +8,9 @@ import { IoTextOutline } from 'react-icons/io5';
|
||||
import { Switch } from '@headlessui/react';
|
||||
import useExamEditorStore from '@/stores/examEditor';
|
||||
import { Module } from '@/interfaces';
|
||||
import { capitalize } from 'lodash';
|
||||
import Select from '@/components/Low/Select';
|
||||
import { Difficulty } from '@/interfaces/exam';
|
||||
|
||||
interface Props {
|
||||
module: Module;
|
||||
@@ -36,6 +39,16 @@ const ExerciseWizard: React.FC<Props> = ({
|
||||
onDiscard,
|
||||
}) => {
|
||||
const [configurations, setConfigurations] = useState<ExerciseConfig[]>([]);
|
||||
const { currentModule } = useExamEditorStore();
|
||||
const { difficulty } = useExamEditorStore(state => state.modules[currentModule]);
|
||||
|
||||
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];
|
||||
|
||||
useEffect(() => {
|
||||
const initialConfigs = selectedExercises.map(exerciseType => {
|
||||
@@ -164,7 +177,7 @@ const ExerciseWizard: React.FC<Props> = ({
|
||||
);
|
||||
}
|
||||
|
||||
const inputValue = Number(config.params[param.param || '1'].toString());
|
||||
const inputValue = Number(config.params[param.param || '1'].toString()) || config.params[param.param!];
|
||||
const isParagraphMatch = config.type.split("?name=")[1] === "paragraphMatch";
|
||||
const maxParagraphs = isParagraphMatch ? extraArgs!.text.split("\n\n").length : 50;
|
||||
|
||||
@@ -183,9 +196,23 @@ const ExerciseWizard: React.FC<Props> = ({
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{param.param === "difficulty" ?
|
||||
<Select
|
||||
options={DIFFICULTIES.map((x) => ({ value: x, label: x }))}
|
||||
onChange={(value) => {
|
||||
handleParameterChange(
|
||||
exerciseIndex,
|
||||
param.param || '',
|
||||
value?.value || ''
|
||||
);
|
||||
}}
|
||||
value={{ value: config.params[param.param] !== "" ? config.params[param.param] as string : randomDiff , label: config.params[param.param] !== "" ? config.params[param.param] as string : randomDiff }}
|
||||
flat
|
||||
/>
|
||||
:
|
||||
<input
|
||||
type="number"
|
||||
value={inputValue}
|
||||
value={inputValue as number}
|
||||
onChange={(e) => handleParameterChange(
|
||||
exerciseIndex,
|
||||
param.param || '',
|
||||
@@ -195,6 +222,8 @@ const ExerciseWizard: React.FC<Props> = ({
|
||||
min={1}
|
||||
max={maxParagraphs}
|
||||
/>
|
||||
}
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
FaQuestionCircle,
|
||||
} from 'react-icons/fa';
|
||||
import { ExerciseGen } from './generatedExercises';
|
||||
import { MdRadioButtonChecked } from 'react-icons/md';
|
||||
import { BsListCheck } from 'react-icons/bs';
|
||||
|
||||
const quantity = (quantity: number, tooltip?: string) => {
|
||||
@@ -32,6 +31,14 @@ const quantity = (quantity: number, tooltip?: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const difficulty = () => {
|
||||
return {
|
||||
param: "difficulty",
|
||||
label: "Difficulty",
|
||||
tooltip: "Exercise difficulty",
|
||||
}
|
||||
}
|
||||
|
||||
const generate = () => {
|
||||
return {
|
||||
param: "generate",
|
||||
@@ -52,6 +59,7 @@ const reading = (passage: number) => {
|
||||
value: "multipleChoice"
|
||||
},
|
||||
quantity(5, "Quantity of Multiple Choice Questions"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "reading"
|
||||
@@ -73,6 +81,7 @@ const reading = (passage: number) => {
|
||||
value: 1
|
||||
},
|
||||
quantity(4, "Quantity of Blanks"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "reading"
|
||||
@@ -94,6 +103,7 @@ const reading = (passage: number) => {
|
||||
value: 3
|
||||
},
|
||||
quantity(4, "Quantity of Blanks"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "reading"
|
||||
@@ -109,6 +119,7 @@ const reading = (passage: number) => {
|
||||
value: "trueFalse"
|
||||
},
|
||||
quantity(4, "Quantity of Statements"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "reading"
|
||||
@@ -124,6 +135,7 @@ const reading = (passage: number) => {
|
||||
value: "paragraphMatch"
|
||||
},
|
||||
quantity(5, "Quantity of Matches"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "reading"
|
||||
@@ -143,6 +155,7 @@ const reading = (passage: number) => {
|
||||
value: "ideaMatch"
|
||||
},
|
||||
quantity(5, "Quantity of Ideas"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "reading"
|
||||
@@ -165,6 +178,7 @@ const listening = (section: number) => {
|
||||
value: section == 3 ? "multipleChoice3Options" : "multipleChoice"
|
||||
},
|
||||
quantity(5, "Quantity of Multiple Choice Questions"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "listening"
|
||||
@@ -180,6 +194,7 @@ const listening = (section: number) => {
|
||||
value: "writeBlanksQuestions"
|
||||
},
|
||||
quantity(5, "Quantity of Blanks"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "listening"
|
||||
@@ -195,6 +210,7 @@ const listening = (section: number) => {
|
||||
value: "trueFalse"
|
||||
},
|
||||
quantity(4, "Quantity of Statements"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "listening"
|
||||
@@ -214,6 +230,7 @@ const listening = (section: number) => {
|
||||
value: "writeBlanksFill"
|
||||
},
|
||||
quantity(5, "Quantity of Blanks"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "listening"
|
||||
@@ -231,6 +248,7 @@ const listening = (section: number) => {
|
||||
value: "writeBlanksForm"
|
||||
},
|
||||
quantity(5, "Quantity of Blanks"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "listening"
|
||||
@@ -251,6 +269,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
value: "multipleChoice"
|
||||
},
|
||||
quantity(10, "Amount"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "level"
|
||||
@@ -265,6 +284,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
value: "mcBlank"
|
||||
},
|
||||
quantity(10, "Amount"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "level"
|
||||
@@ -279,6 +299,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
value: "mcUnderline"
|
||||
},
|
||||
quantity(10, "Amount"),
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "level"
|
||||
@@ -294,6 +315,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
param: "text_size",
|
||||
value: "250"
|
||||
},
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "level"
|
||||
@@ -313,6 +335,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
param: "text_size",
|
||||
value: "250"
|
||||
},
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "level"
|
||||
@@ -345,6 +368,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
param: "text_size",
|
||||
value: "700"
|
||||
},
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "level"
|
||||
@@ -360,6 +384,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
value: "",
|
||||
type: "text"
|
||||
},
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "writing"
|
||||
@@ -375,6 +400,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
value: "",
|
||||
type: "text"
|
||||
},
|
||||
difficulty(),
|
||||
generate()
|
||||
],
|
||||
module: "writing"
|
||||
@@ -384,6 +410,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
type: "speaking_1",
|
||||
icon: FaComments,
|
||||
extra: [
|
||||
difficulty(),
|
||||
generate(),
|
||||
{
|
||||
label: "First Topic",
|
||||
@@ -405,6 +432,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
type: "speaking_2",
|
||||
icon: FaUserFriends,
|
||||
extra: [
|
||||
difficulty(),
|
||||
generate(),
|
||||
{
|
||||
label: "Topic",
|
||||
@@ -420,6 +448,7 @@ const EXERCISES: ExerciseGen[] = [
|
||||
type: "speaking_3",
|
||||
icon: FaHandshake,
|
||||
extra: [
|
||||
difficulty(),
|
||||
generate(),
|
||||
{
|
||||
label: "Topic",
|
||||
|
||||
@@ -17,6 +17,6 @@ export interface ExerciseGen {
|
||||
type: string;
|
||||
icon: IconType;
|
||||
sectionId?: number;
|
||||
extra?: { param?: string; value?: string | number | boolean; label?: string; tooltip?: string, type?: string}[];
|
||||
extra?: { param: string; value?: string | number | boolean; label?: string; tooltip?: string, type?: string}[];
|
||||
module: string
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import { BsArrowRepeat } from "react-icons/bs";
|
||||
interface ExercisePickerProps {
|
||||
module: string;
|
||||
sectionId: number;
|
||||
difficulty: string;
|
||||
extraArgs?: Record<string, any>;
|
||||
levelSectionId?: number;
|
||||
level?: boolean;
|
||||
}
|
||||
|
||||
const DIFFICULTIES: string[] = ["A1", "A2", "B1", "B2", "C1", "C2"];
|
||||
|
||||
const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
module,
|
||||
sectionId,
|
||||
@@ -26,7 +27,7 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
levelSectionId,
|
||||
level = false
|
||||
}) => {
|
||||
const { currentModule, dispatch } = useExamEditorStore();
|
||||
const { currentModule } = useExamEditorStore();
|
||||
const { difficulty, sections } = useExamEditorStore((store) => store.modules[level ? "level" : currentModule]);
|
||||
const section = sections.find((s) => s.sectionId === (level ? levelSectionId : sectionId));
|
||||
|
||||
@@ -67,6 +68,9 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
}),
|
||||
...(config.params.max_words !== undefined && {
|
||||
max_words: Number(config.params.max_words)
|
||||
}),
|
||||
...(DIFFICULTIES.includes(config.params.difficulty as string) && {
|
||||
difficulty: config.params.difficulty
|
||||
})
|
||||
};
|
||||
});
|
||||
@@ -100,8 +104,8 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
method: 'POST',
|
||||
body: {
|
||||
...context,
|
||||
exercises: exercises,
|
||||
difficulty: difficulty
|
||||
exercises,
|
||||
difficulty
|
||||
}
|
||||
},
|
||||
(data: any) => [{
|
||||
@@ -112,7 +116,11 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
);
|
||||
} else if (module === "writing") {
|
||||
configurations.forEach((config) => {
|
||||
let queryParams = config.params.topic !== '' ? { topic: config.params.topic as string } : undefined;
|
||||
let queryParams = {
|
||||
difficulty: config.params.difficulty ? config.params.difficulty as string: difficulty,
|
||||
...(config.params.topic !== '' && { topic: config.params.topic as string })
|
||||
};
|
||||
|
||||
generate(
|
||||
config.type === 'writing_letter' ? 1 : 2,
|
||||
"writing",
|
||||
@@ -122,7 +130,8 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
queryParams
|
||||
},
|
||||
(data: any) => [{
|
||||
prompt: data.question
|
||||
prompt: data.question,
|
||||
difficulty: data.difficulty
|
||||
}],
|
||||
levelSectionId,
|
||||
level
|
||||
@@ -135,6 +144,7 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
topic: config.params.topic as string,
|
||||
first_topic: config.params.first_topic as string,
|
||||
second_topic: config.params.second_topic as string,
|
||||
difficulty: config.params.difficulty ? config.params.difficulty as string: difficulty,
|
||||
}).filter(([_, value]) => value && value !== '')
|
||||
);
|
||||
let query = Object.keys(queryParams).length === 0 ? undefined : queryParams;
|
||||
@@ -152,19 +162,22 @@ const ExercisePicker: React.FC<ExercisePickerProps> = ({
|
||||
return [{
|
||||
prompts: data.questions,
|
||||
first_topic: data.first_topic,
|
||||
second_topic: data.second_topic
|
||||
second_topic: data.second_topic,
|
||||
difficulty: data.difficulty
|
||||
}];
|
||||
case 2:
|
||||
return [{
|
||||
topic: data.topic,
|
||||
question: data.question,
|
||||
prompts: data.prompts,
|
||||
suffix: data.suffix
|
||||
suffix: data.suffix,
|
||||
difficulty: data.difficulty
|
||||
}];
|
||||
case 3:
|
||||
return [{
|
||||
topic: data.topic,
|
||||
questions: data.questions
|
||||
questions: data.questions,
|
||||
difficulty: data.difficulty
|
||||
}];
|
||||
default:
|
||||
return [data];
|
||||
|
||||
Reference in New Issue
Block a user