Updated the generation to allow for private exams

This commit is contained in:
Tiago Ribeiro
2024-08-28 10:46:02 +01:00
parent dbf262598f
commit e518323d99
6 changed files with 78 additions and 29 deletions

View File

@@ -1,3 +1,4 @@
import Checkbox from "@/components/Low/Checkbox";
import Input from "@/components/Low/Input";
import Select from "@/components/Low/Select";
import {Difficulty, Exercise, InteractiveSpeakingExercise, SpeakingExam, SpeakingExercise} from "@/interfaces/exam";
@@ -225,7 +226,7 @@ interface Props {
id: string;
}
const SpeakingGeneration = ({ id } : Props) => {
const SpeakingGeneration = ({id}: Props) => {
const [part1, setPart1] = useState<SpeakingPart>();
const [part2, setPart2] = useState<SpeakingPart>();
const [part3, setPart3] = useState<SpeakingPart>();
@@ -233,6 +234,7 @@ const SpeakingGeneration = ({ id } : Props) => {
const [isLoading, setIsLoading] = useState(false);
const [resultingExam, setResultingExam] = useState<SpeakingExam>();
const [difficulty, setDifficulty] = useState<Difficulty>(sample(DIFFICULTIES)!);
const [isPrivate, setPrivate] = useState<boolean>(false);
useEffect(() => {
const parts = [part1, part2, part3].filter((x) => !!x);
@@ -247,11 +249,11 @@ const SpeakingGeneration = ({ id } : Props) => {
const submitExam = () => {
if (!part1?.result && !part2?.result && !part3?.result) return toast.error("Please generate at least one task!");
if(!id) {
if (!id) {
toast.error("Please insert a title before submitting");
return;
}
setIsLoading(true);
const genders = [part1?.gender, part2?.gender, part3?.gender].filter((x) => !!x);
@@ -272,6 +274,7 @@ const SpeakingGeneration = ({ id } : Props) => {
variant: minTimer >= 14 ? "full" : "partial",
module: "speaking",
instructorGender: genders.every((x) => x === "male") ? "male" : genders.every((x) => x === "female") ? "female" : "varied",
private: isPrivate,
};
axios
@@ -313,7 +316,7 @@ const SpeakingGeneration = ({ id } : Props) => {
return (
<>
<div className="flex gap-4 w-1/2">
<div className="flex gap-4 w-full items-center">
<div className="flex flex-col gap-3">
<label className="font-normal text-base text-mti-gray-dim">Timer</label>
<Input
@@ -324,7 +327,7 @@ const SpeakingGeneration = ({ id } : Props) => {
className="max-w-[300px]"
/>
</div>
<div className="flex flex-col gap-3 w-full">
<div className="flex flex-col gap-3 w-1/2">
<label className="font-normal text-base text-mti-gray-dim">Difficulty</label>
<Select
options={DIFFICULTIES.map((x) => ({
@@ -336,6 +339,13 @@ const SpeakingGeneration = ({ id } : Props) => {
disabled={!!part1 || !!part2 || !!part3}
/>
</div>
<div className="flex flex-col gap-3 w-fit h-fit">
<div className="h-6" />
<Checkbox isChecked={isPrivate} onChange={setPrivate}>
Privacy (Only available for Assignments)
</Checkbox>
</div>
</div>
<Tab.Group>