Updated and fixed the level generation

This commit is contained in:
Tiago Ribeiro
2024-07-26 23:43:23 +01:00
parent 8f6639b7fc
commit a6160c3cf0
4 changed files with 19 additions and 12 deletions

View File

@@ -43,7 +43,7 @@ const QuestionDisplay = ({question, onUpdate}: {question: MultipleChoiceQuestion
const [answer, setAnswer] = useState(question.solution);
const renderPrompt = (prompt: string) => {
return reactStringReplace(prompt, /((<u>)\w+(<\/u>))/g, (match) => {
return reactStringReplace(prompt, /((<u>)[\w\s']+(<\/u>))/g, (match) => {
const word = match.replaceAll("<u>", "").replaceAll("</u>", "");
return word.length > 0 ? <u>{word}</u> : null;
});
@@ -280,6 +280,8 @@ const LevelGeneration = () => {
axios
.post<{exercises: {[key: string]: any}}>("/api/exam/level/generate/level", {nr_exercises: numberOfParts, ...body})
.then((result) => {
console.log(result.data);
playSound(typeof result.data === "string" ? "error" : "check");
if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again.");
@@ -305,7 +307,7 @@ const LevelGeneration = () => {
part.type === "multiple_choice_underlined"
? "Select the wrong part of the sentence."
: "Select the appropriate option.",
questions: currentExercise.questions,
questions: currentExercise.questions.map((x: any) => ({...x, variant: "text"})),
type: "multipleChoice",
userSolutions: [],
};
@@ -357,7 +359,7 @@ const LevelGeneration = () => {
const mcExercise: MultipleChoiceExercise = {
id: v4(),
prompt: "Select the appropriate option.",
questions: currentExercise.exercises.multipleChoice,
questions: currentExercise.exercises.multipleChoice.questions.map((x: any) => ({...x, variant: "text"})),
type: "multipleChoice",
userSolutions: [],
};