Updated the color of the task response
This commit is contained in:
@@ -124,7 +124,7 @@ export default function Writing({id, type, prompt, attachment, userSolutions, on
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-ielts-speaking text-ielts-speaking-light rounded-xl px-4 py-2",
|
"bg-ielts-writing text-ielts-writing-light rounded-xl px-4 py-2",
|
||||||
typeof taskResponse !== "number" && "tooltip",
|
typeof taskResponse !== "number" && "tooltip",
|
||||||
)}
|
)}
|
||||||
data-tip={typeof taskResponse !== "number" ? taskResponse.comment : ""}
|
data-tip={typeof taskResponse !== "number" ? taskResponse.comment : ""}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
import Select from "@/components/Low/Select";
|
import Select from "@/components/Low/Select";
|
||||||
import {
|
import {Difficulty, LevelExam, MultipleChoiceExercise, MultipleChoiceQuestion, LevelPart} from "@/interfaces/exam";
|
||||||
Difficulty,
|
|
||||||
LevelExam,
|
|
||||||
MultipleChoiceExercise,
|
|
||||||
MultipleChoiceQuestion,
|
|
||||||
LevelPart,
|
|
||||||
} from "@/interfaces/exam";
|
|
||||||
import useExamStore from "@/stores/examStore";
|
import useExamStore from "@/stores/examStore";
|
||||||
import {getExamById} from "@/utils/exams";
|
import {getExamById} from "@/utils/exams";
|
||||||
import {playSound} from "@/utils/sound";
|
import {playSound} from "@/utils/sound";
|
||||||
@@ -21,13 +15,7 @@ import { v4 } from "uuid";
|
|||||||
|
|
||||||
const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"];
|
const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"];
|
||||||
|
|
||||||
const QuestionDisplay = ({
|
const QuestionDisplay = ({question, onUpdate}: {question: MultipleChoiceQuestion; onUpdate: (question: MultipleChoiceQuestion) => void}) => {
|
||||||
question,
|
|
||||||
onUpdate,
|
|
||||||
}: {
|
|
||||||
question: MultipleChoiceQuestion;
|
|
||||||
onUpdate: (question: MultipleChoiceQuestion) => void;
|
|
||||||
}) => {
|
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [options, setOptions] = useState(question.options);
|
const [options, setOptions] = useState(question.options);
|
||||||
const [answer, setAnswer] = useState(question.solution);
|
const [answer, setAnswer] = useState(question.solution);
|
||||||
@@ -39,32 +27,17 @@ const QuestionDisplay = ({
|
|||||||
</span>
|
</span>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
{question.options.map((option, index) => (
|
{question.options.map((option, index) => (
|
||||||
|
<span key={option.id} className={clsx(answer === option.id && "font-bold")}>
|
||||||
<span
|
<span
|
||||||
key={option.id}
|
className={clsx("font-semibold", answer === option.id ? "text-mti-green-light" : "text-ielts-level")}
|
||||||
className={clsx(answer === option.id && "font-bold")}
|
onClick={() => setAnswer(option.id)}>
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={clsx(
|
|
||||||
"font-semibold",
|
|
||||||
answer === option.id
|
|
||||||
? "text-mti-green-light"
|
|
||||||
: "text-ielts-level"
|
|
||||||
)}
|
|
||||||
onClick={() => setAnswer(option.id)}
|
|
||||||
>
|
|
||||||
({option.id})
|
({option.id})
|
||||||
</span>{" "}
|
</span>{" "}
|
||||||
{isEditing ? (
|
{isEditing ? (
|
||||||
<input
|
<input
|
||||||
defaultValue={option.text}
|
defaultValue={option.text}
|
||||||
className="w-60"
|
className="w-60"
|
||||||
onChange={(e) =>
|
onChange={(e) => setOptions((prev) => prev.map((x, idx) => (idx === index ? {...x, text: e.target.value} : x)))}
|
||||||
setOptions((prev) =>
|
|
||||||
prev.map((x, idx) =>
|
|
||||||
idx === index ? { ...x, text: e.target.value } : x
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<span>{option.text}</span>
|
<span>{option.text}</span>
|
||||||
@@ -76,8 +49,7 @@ const QuestionDisplay = ({
|
|||||||
{!isEditing && (
|
{!isEditing && (
|
||||||
<button
|
<button
|
||||||
onClick={() => setIsEditing(true)}
|
onClick={() => setIsEditing(true)}
|
||||||
className="p-2 border border-neutral-300 bg-white rounded-xl hover:drop-shadow transition ease-in-out duration-300"
|
className="p-2 border border-neutral-300 bg-white rounded-xl hover:drop-shadow transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsPencilSquare />
|
<BsPencilSquare />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
@@ -88,14 +60,12 @@ const QuestionDisplay = ({
|
|||||||
onUpdate({...question, options, solution: answer});
|
onUpdate({...question, options, solution: answer});
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
}}
|
}}
|
||||||
className="p-2 border border-neutral-300 bg-white rounded-xl hover:drop-shadow transition ease-in-out duration-300"
|
className="p-2 border border-neutral-300 bg-white rounded-xl hover:drop-shadow transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsCheck />
|
<BsCheck />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => setIsEditing(false)}
|
onClick={() => setIsEditing(false)}
|
||||||
className="p-2 border border-neutral-300 bg-white rounded-xl hover:drop-shadow transition ease-in-out duration-300"
|
className="p-2 border border-neutral-300 bg-white rounded-xl hover:drop-shadow transition ease-in-out duration-300">
|
||||||
>
|
|
||||||
<BsX />
|
<BsX />
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
@@ -105,15 +75,7 @@ const QuestionDisplay = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const TaskTab = ({
|
const TaskTab = ({exam, difficulty, setExam}: {exam?: LevelPart; difficulty: Difficulty; setExam: (exam: LevelPart) => void}) => {
|
||||||
exam,
|
|
||||||
difficulty,
|
|
||||||
setExam,
|
|
||||||
}: {
|
|
||||||
exam?: LevelPart;
|
|
||||||
difficulty: Difficulty;
|
|
||||||
setExam: (exam: LevelPart) => void;
|
|
||||||
}) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const generate = () => {
|
const generate = () => {
|
||||||
@@ -124,11 +86,9 @@ const TaskTab = ({
|
|||||||
axios
|
axios
|
||||||
.get(`/api/exam/level/generate/level?${url.toString()}`)
|
.get(`/api/exam/level/generate/level?${url.toString()}`)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
console.log({data: result.data});
|
||||||
playSound(typeof result.data === "string" ? "error" : "check");
|
playSound(typeof result.data === "string" ? "error" : "check");
|
||||||
if (typeof result.data === "string")
|
if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate again.");
|
||||||
return toast.error(
|
|
||||||
"Something went wrong, please try to generate again."
|
|
||||||
);
|
|
||||||
setExam(result.data);
|
setExam(result.data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -145,11 +105,8 @@ const TaskTab = ({
|
|||||||
...exam,
|
...exam,
|
||||||
exercises: exam.exercises.map((x) => ({
|
exercises: exam.exercises.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
questions: (x as MultipleChoiceExercise).questions.map((q) =>
|
questions: (x as MultipleChoiceExercise).questions.map((q) => (q.id === question.id ? question : q)),
|
||||||
q.id === question.id ? question : q
|
})),
|
||||||
),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
console.log(updatedExam);
|
console.log(updatedExam);
|
||||||
setExam(updatedExam as any);
|
setExam(updatedExam as any);
|
||||||
@@ -164,9 +121,8 @@ const TaskTab = ({
|
|||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-ielts-level/70 border border-ielts-level text-white w-full px-6 py-6 rounded-xl h-[70px]",
|
"bg-ielts-level/70 border border-ielts-level text-white w-full px-6 py-6 rounded-xl h-[70px]",
|
||||||
"hover:bg-ielts-level disabled:bg-ielts-level/40 disabled:cursor-not-allowed",
|
"hover:bg-ielts-level disabled:bg-ielts-level/40 disabled:cursor-not-allowed",
|
||||||
"transition ease-in-out duration-300"
|
"transition ease-in-out duration-300",
|
||||||
)}
|
)}>
|
||||||
>
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="flex items-center justify-center">
|
<div className="flex items-center justify-center">
|
||||||
<BsArrowRepeat className="text-white animate-spin" size={25} />
|
<BsArrowRepeat className="text-white animate-spin" size={25} />
|
||||||
@@ -178,12 +134,8 @@ const TaskTab = ({
|
|||||||
</div>
|
</div>
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div className="w-fit h-fit mt-12 self-center animate-pulse flex flex-col gap-8 items-center">
|
<div className="w-fit h-fit mt-12 self-center animate-pulse flex flex-col gap-8 items-center">
|
||||||
<span
|
<span className={clsx("loading loading-infinity w-32 text-ielts-level")} />
|
||||||
className={clsx("loading loading-infinity w-32 text-ielts-level")}
|
<span className={clsx("font-bold text-2xl text-ielts-level")}>Generating...</span>
|
||||||
/>
|
|
||||||
<span className={clsx("font-bold text-2xl text-ielts-level")}>
|
|
||||||
Generating...
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{exam && (
|
{exam && (
|
||||||
@@ -196,20 +148,14 @@ const TaskTab = ({
|
|||||||
return (
|
return (
|
||||||
<div key={ex.id} className="w-full h-full flex flex-col gap-2">
|
<div key={ex.id} className="w-full h-full flex flex-col gap-2">
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<span className="text-xl font-semibold">
|
<span className="text-xl font-semibold">Multiple Choice</span>
|
||||||
Multiple Choice
|
|
||||||
</span>
|
|
||||||
<span className="rounded-xl bg-white border border-ielts-level p-1 px-4 w-fit">
|
<span className="rounded-xl bg-white border border-ielts-level p-1 px-4 w-fit">
|
||||||
{exercise.questions.length} questions
|
{exercise.questions.length} questions
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{exercise.questions.map((question) => (
|
{exercise.questions.map((question) => (
|
||||||
<QuestionDisplay
|
<QuestionDisplay question={question} onUpdate={onUpdate} key={question.id} />
|
||||||
question={question}
|
|
||||||
onUpdate={onUpdate}
|
|
||||||
key={question.id}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -225,9 +171,7 @@ const LevelGeneration = () => {
|
|||||||
const [generatedExam, setGeneratedExam] = useState<LevelPart>();
|
const [generatedExam, setGeneratedExam] = useState<LevelPart>();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [resultingExam, setResultingExam] = useState<LevelExam>();
|
const [resultingExam, setResultingExam] = useState<LevelExam>();
|
||||||
const [difficulty, setDifficulty] = useState<Difficulty>(
|
const [difficulty, setDifficulty] = useState<Difficulty>(sample(DIFFICULTIES)!);
|
||||||
sample(DIFFICULTIES)!
|
|
||||||
);
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -237,12 +181,9 @@ const LevelGeneration = () => {
|
|||||||
const loadExam = async (examId: string) => {
|
const loadExam = async (examId: string) => {
|
||||||
const exam = await getExamById("level", examId.trim());
|
const exam = await getExamById("level", examId.trim());
|
||||||
if (!exam) {
|
if (!exam) {
|
||||||
toast.error(
|
toast.error("Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID", {
|
||||||
"Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID",
|
|
||||||
{
|
|
||||||
toastId: "invalid-exam-id",
|
toastId: "invalid-exam-id",
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -274,18 +215,14 @@ const LevelGeneration = () => {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
playSound("sent");
|
playSound("sent");
|
||||||
console.log(`Generated Exam ID: ${result.data.id}`);
|
console.log(`Generated Exam ID: ${result.data.id}`);
|
||||||
toast.success(
|
toast.success("This new exam has been generated successfully! Check the ID in our browser's console.");
|
||||||
"This new exam has been generated successfully! Check the ID in our browser's console."
|
|
||||||
);
|
|
||||||
setResultingExam(result.data);
|
setResultingExam(result.data);
|
||||||
|
|
||||||
setGeneratedExam(undefined);
|
setGeneratedExam(undefined);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
toast.error(
|
toast.error("Something went wrong while generating, please try again later.");
|
||||||
"Something went wrong while generating, please try again later."
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.finally(() => setIsLoading(false));
|
.finally(() => setIsLoading(false));
|
||||||
};
|
};
|
||||||
@@ -294,17 +231,13 @@ const LevelGeneration = () => {
|
|||||||
<>
|
<>
|
||||||
<div className="flex gap-4 w-1/2">
|
<div className="flex gap-4 w-1/2">
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex flex-col gap-3 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Difficulty</label>
|
||||||
Difficulty
|
|
||||||
</label>
|
|
||||||
<Select
|
<Select
|
||||||
options={DIFFICULTIES.map((x) => ({
|
options={DIFFICULTIES.map((x) => ({
|
||||||
value: x,
|
value: x,
|
||||||
label: capitalize(x),
|
label: capitalize(x),
|
||||||
}))}
|
}))}
|
||||||
onChange={(value) =>
|
onChange={(value) => (value ? setDifficulty(value.value as Difficulty) : null)}
|
||||||
value ? setDifficulty(value.value as Difficulty) : null
|
|
||||||
}
|
|
||||||
value={{value: difficulty, label: capitalize(difficulty)}}
|
value={{value: difficulty, label: capitalize(difficulty)}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -317,21 +250,14 @@ const LevelGeneration = () => {
|
|||||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-level/70",
|
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-level/70",
|
||||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-level focus:outline-none focus:ring-2",
|
"ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-level focus:outline-none focus:ring-2",
|
||||||
"transition duration-300 ease-in-out",
|
"transition duration-300 ease-in-out",
|
||||||
selected
|
selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-level",
|
||||||
? "bg-white shadow"
|
|
||||||
: "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-level"
|
|
||||||
)
|
)
|
||||||
}
|
}>
|
||||||
>
|
|
||||||
Exam
|
Exam
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tab.List>
|
</Tab.List>
|
||||||
<Tab.Panels>
|
<Tab.Panels>
|
||||||
<TaskTab
|
<TaskTab difficulty={difficulty} exam={generatedExam} setExam={setGeneratedExam} />
|
||||||
difficulty={difficulty}
|
|
||||||
exam={generatedExam}
|
|
||||||
setExam={setGeneratedExam}
|
|
||||||
/>
|
|
||||||
</Tab.Panels>
|
</Tab.Panels>
|
||||||
</Tab.Group>
|
</Tab.Group>
|
||||||
<div className="w-full flex justify-end gap-4">
|
<div className="w-full flex justify-end gap-4">
|
||||||
@@ -342,9 +268,8 @@ const LevelGeneration = () => {
|
|||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-white border border-ielts-level text-ielts-level w-full max-w-[200px] rounded-xl h-[70px] self-end",
|
"bg-white border border-ielts-level text-ielts-level w-full max-w-[200px] rounded-xl h-[70px] self-end",
|
||||||
"hover:bg-ielts-level hover:text-white disabled:bg-ielts-level/40 disabled:cursor-not-allowed",
|
"hover:bg-ielts-level hover:text-white disabled:bg-ielts-level/40 disabled:cursor-not-allowed",
|
||||||
"transition ease-in-out duration-300"
|
"transition ease-in-out duration-300",
|
||||||
)}
|
)}>
|
||||||
>
|
|
||||||
Perform Exam
|
Perform Exam
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
@@ -356,9 +281,8 @@ const LevelGeneration = () => {
|
|||||||
"bg-ielts-level/70 border border-ielts-level text-white w-full max-w-[200px] rounded-xl h-[70px] self-end",
|
"bg-ielts-level/70 border border-ielts-level text-white w-full max-w-[200px] rounded-xl h-[70px] self-end",
|
||||||
"hover:bg-ielts-level disabled:bg-ielts-level/40 disabled:cursor-not-allowed",
|
"hover:bg-ielts-level disabled:bg-ielts-level/40 disabled:cursor-not-allowed",
|
||||||
"transition ease-in-out duration-300",
|
"transition ease-in-out duration-300",
|
||||||
!generatedExam && "tooltip"
|
!generatedExam && "tooltip",
|
||||||
)}
|
)}>
|
||||||
>
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="flex items-center justify-center">
|
<div className="flex items-center justify-center">
|
||||||
<BsArrowRepeat className="text-white animate-spin" size={25} />
|
<BsArrowRepeat className="text-white animate-spin" size={25} />
|
||||||
|
|||||||
Reference in New Issue
Block a user