From 3da87cce6002c1f5ccf265db3d1e9ba2e4886c92 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Thu, 4 Jul 2024 00:19:07 +0100 Subject: [PATCH] Added write blanks edit --- .../Generation/white.blanks.edit.tsx | 7 -- .../Generation/write.blanks.edit.tsx | 94 +++++++++++++++++++ src/pages/(generation)/ReadingGeneration.tsx | 23 +++++ 3 files changed, 117 insertions(+), 7 deletions(-) delete mode 100644 src/components/Generation/white.blanks.edit.tsx create mode 100644 src/components/Generation/write.blanks.edit.tsx diff --git a/src/components/Generation/white.blanks.edit.tsx b/src/components/Generation/white.blanks.edit.tsx deleted file mode 100644 index 9bf8ce63..00000000 --- a/src/components/Generation/white.blanks.edit.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -const WhiteBlankEdits = () => { - return null; -} - -export default WhiteBlankEdits; \ No newline at end of file diff --git a/src/components/Generation/write.blanks.edit.tsx b/src/components/Generation/write.blanks.edit.tsx new file mode 100644 index 00000000..d682743b --- /dev/null +++ b/src/components/Generation/write.blanks.edit.tsx @@ -0,0 +1,94 @@ +import React from "react"; +import Input from "@/components/Low/Input"; +import { WriteBlanksExercise } from "@/interfaces/exam"; + +interface Props { + exercise: WriteBlanksExercise; + updateExercise: (data: any) => void; +} +const WriteBlankEdits = (props: Props) => { + const { exercise, updateExercise } = props; + + return ( + <> + + updateExercise({ + prompt: value, + }) + } + /> + + updateExercise({ + text: value, + }) + } + /> + + updateExercise({ + maxWords: Number(value), + }) + } + /> +

Solutions

+
+ {exercise.solutions.map((solution) => ( +
+ Solution ID: {solution.id} + {/* TODO: Consider adding an add and delete button */} +
+ {solution.solution.map((sol, solIndex) => ( + + updateExercise({ + solutions: exercise.solutions.map((iSol) => + iSol.id === solution.id + ? { + ...iSol, + solution: iSol.solution.map((iiSol, iiIndex) => { + if (iiIndex === solIndex) { + return value; + } + + return iiSol; + }), + } + : iSol + ), + }) + } + className="sm:w-1/2 lg:w-1/4 px-2" + /> + ))} +
+
+ ))} +
+ + ); +}; + +export default WriteBlankEdits; diff --git a/src/pages/(generation)/ReadingGeneration.tsx b/src/pages/(generation)/ReadingGeneration.tsx index a4581a2e..67bb431f 100644 --- a/src/pages/(generation)/ReadingGeneration.tsx +++ b/src/pages/(generation)/ReadingGeneration.tsx @@ -21,6 +21,7 @@ import { toast } from "react-toastify"; import { v4 } from "uuid"; import FillBlanksEdit from "@/components/Generation/fill.blanks.edit"; import TrueFalseEdit from "@/components/Generation/true.false.edit"; +import WriteBlanksEdit from "@/components/Generation/write.blanks.edit"; const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"]; @@ -119,6 +120,28 @@ const PartTab = ({ /> ); + case "writeBlanks": + return ( + <> +

Exercise: Write Blanks

+ { + updatePart((part?: ReadingPart) => { + if (part) { + return { + ...part, + exercises: part.exercises.map((x) => + x.id === exercise.id ? { ...x, ...data } : x + ), + } as ReadingPart; + } + }); + }} + /> + + ); default: return null; }