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>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user