Created a prototype for one exercise of the reading module

This commit is contained in:
Tiago Ribeiro
2023-03-21 17:09:35 +00:00
parent be7665fab8
commit 740346f696
8 changed files with 414 additions and 4 deletions

116
src/pages/exam/index.tsx Normal file
View File

@@ -0,0 +1,116 @@
/* eslint-disable @next/next/no-img-element */
import Head from "next/head";
import Navbar from "@/components/Navbar";
import Icon from "@mdi/react";
import {mdiAccountVoice, mdiArrowLeft, mdiArrowRight, mdiBookOpen, mdiHeadphones, mdiPen} from "@mdi/js";
import {useState} from "react";
import {Module} from "@/interfaces";
import clsx from "clsx";
import {useRouter} from "next/router";
import {errorButtonStyle, infoButtonStyle} from "@/constants/buttonStyles";
import ProfileLevel from "@/components/ProfileLevel";
// TODO: Remove this import
import JSON_USER from "@/demo/user.json";
export default function Home() {
const [selectedModules, setSelectedModules] = useState<Module[]>([]);
const router = useRouter();
const toggleModule = (module: Module) => {
const modules = selectedModules.filter((x) => x !== module);
setSelectedModules((prev) => (prev.includes(module) ? modules : [...modules, module]));
};
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="w-full h-screen flex flex-col items-center bg-neutral-100 text-black">
<Navbar profilePicture={JSON_USER.profilePicture} />
<div className="w-full h-full relative">
<section className="h-full w-full flex flex-col items-center justify-center">
{/* //TODO: Change this section to work with the user account */}
<ProfileLevel user={JSON_USER} className="h-1/2" />
<div className="h-1/2 flex flex-col">
<div className="h-1/2 flex gap-8">
<div
role="button"
tabIndex={0}
onClick={() => toggleModule("reading")}
className={clsx(
"flex flex-col gap-2 items-center justify-center",
"border-ielts-reading hover:bg-ielts-reading text-white",
"border-2 rounded-xl p-4 h-fit w-48 cursor-pointer",
selectedModules.includes("reading") ? "bg-ielts-reading " : "bg-ielts-reading-transparent ",
)}>
<Icon path={mdiBookOpen} color="white" size={3} />
<span>Reading</span>
</div>
<div
role="button"
tabIndex={0}
onClick={() => toggleModule("listening")}
className={clsx(
"flex flex-col gap-2 items-center justify-center",
"border-ielts-listening hover:bg-ielts-listening text-white",
"border-2 rounded-xl p-4 h-fit w-48 cursor-pointer",
selectedModules.includes("listening") ? "bg-ielts-listening " : "bg-ielts-listening-transparent ",
)}>
<Icon path={mdiHeadphones} color="white" size={3} />
<span>Listening</span>
</div>
<div
role="button"
tabIndex={0}
onClick={() => toggleModule("speaking")}
className={clsx(
"flex flex-col gap-2 items-center justify-center",
"border-ielts-speaking hover:bg-ielts-speaking text-white",
"border-2 rounded-xl p-4 h-fit w-48 cursor-pointer",
selectedModules.includes("speaking") ? "bg-ielts-speaking " : "bg-ielts-speaking-transparent ",
)}>
<Icon path={mdiAccountVoice} color="white" size={3} />
<span>Speaking</span>
</div>
<div
role="button"
tabIndex={0}
onClick={() => toggleModule("writing")}
className={clsx(
"flex flex-col gap-2 items-center justify-center",
"border-ielts-writing hover:bg-ielts-writing text-white",
"border-2 rounded-xl p-4 h-fit w-48 cursor-pointer",
selectedModules.includes("writing") ? "bg-ielts-writing " : "bg-ielts-writing-transparent ",
)}>
<Icon path={mdiPen} color="white" size={3} />
<span>Writing</span>
</div>
</div>
<div className="w-full flex justify-between">
<button onClick={() => router.push("/")} className={clsx("btn btn-wide gap-4 relative text-white", errorButtonStyle)}>
<div className="absolute left-4">
<Icon path={mdiArrowLeft} color="white" size={1} />
</div>
Back
</button>
<button
className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)}
onClick={() => router.push("/exam/reading/demo")}>
Start
<div className="absolute right-4">
<Icon path={mdiArrowRight} color="white" size={1} />
</div>
</button>
</div>
</div>
</section>
</div>
</main>
</>
);
}

View File

@@ -0,0 +1,157 @@
import Navbar from "@/components/Navbar";
import {ReadingExam} from "@/interfaces/exam";
import Head from "next/head";
// TODO: Remove this import
import JSON_READING from "@/demo/reading.json";
import JSON_USER from "@/demo/user.json";
import {Fragment, useState} from "react";
import Icon from "@mdi/react";
import {mdiArrowRight, mdiNotebook} from "@mdi/js";
import clsx from "clsx";
import {infoButtonStyle} from "@/constants/buttonStyles";
import FillBlanks from "@/components/Exercises/FillBlanks";
import {Dialog, Transition} from "@headlessui/react";
interface Props {
exam: ReadingExam;
}
export const getServerSideProps = () => {
return {
props: {
exam: JSON_READING,
},
};
};
function TextModal({isOpen, onClose}: {isOpen: boolean; onClose: () => void}) {
return (
<Transition appear show={isOpen} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={onClose}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0">
<div className="fixed inset-0 bg-black bg-opacity-25" />
</Transition.Child>
<div className="fixed inset-0 overflow-y-auto">
<div className="flex min-h-full items-center justify-center p-4 text-center">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95">
<Dialog.Panel className="w-full max-w-md transform overflow-hidden rounded-2xl bg-white p-6 text-left align-middle shadow-xl transition-all">
<Dialog.Title as="h3" className="text-lg font-medium leading-6 text-gray-900">
Payment successful
</Dialog.Title>
<div className="mt-2">
<p className="text-sm text-gray-500">
Your payment has been successfully submitted. Weve sent you an email with all of the details of your order.
</p>
</div>
<div className="mt-4">
<button
type="button"
className="inline-flex justify-center rounded-md border border-transparent bg-blue-100 px-4 py-2 text-sm font-medium text-blue-900 hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"
onClick={onClose}>
Got it, thanks!
</button>
</div>
</Dialog.Panel>
</Transition.Child>
</div>
</div>
</Dialog>
</Transition>
);
}
export default function Reading({exam}: Props) {
const [exerciseIndex, setExerciseIndex] = useState(-1);
const [showTextModal, setShowTextModal] = useState(false);
const nextExercise = () => {
setExerciseIndex((prev) => prev + 1);
};
const renderText = () => (
<>
<div className="flex flex-col">
<span className="text-lg font-semibold">
Please read the following excerpt attentively, you will then be asked questions about the text you&apos;ve read.
</span>
<span className="self-end text-sm">You will be allowed to read the text while doing the exercises</span>
</div>
<div className="bg-gray-300 rounded-xl p-4 flex flex-col gap-4 items-center w-full overflow-auto">
<span className="text-xl font-semibold">{exam.text.title}</span>
<span>
{exam.text.content.split("\n").map((line) => (
<>
<span>{line}</span>
<br />
</>
))}
</span>
</div>
</>
);
const renderQuestion = () => {
const exercise = exam.exercises[exerciseIndex];
switch (exercise.type) {
case "fillBlanks":
return <FillBlanks {...exercise} />;
}
};
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="w-full h-screen flex flex-col items-center bg-neutral-100 text-black">
<Navbar profilePicture={JSON_USER.profilePicture} />
<TextModal isOpen={showTextModal} onClose={() => setShowTextModal(false)} />
<div className="w-full h-full relative flex flex-col gap-8 items-center justify-center p-8 px-16 overflow-hidden">
{exerciseIndex === -1 && renderText()}
{exerciseIndex > -1 && exerciseIndex < exam.exercises.length && renderQuestion()}
<div className="flex gap-8 self-end">
{exerciseIndex > -1 && (
<button
className={clsx(
"btn btn-wide gap-4 relative text-white",
"border-2 border-ielts-reading hover:bg-ielts-reading hover:border-ielts-reading bg-ielts-reading-transparent",
)}
onClick={() => setShowTextModal(true)}>
Read Text
<div className="absolute right-4">
<Icon path={mdiNotebook} color="white" size={1} />
</div>
</button>
)}
<button className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)} onClick={nextExercise}>
Next
<div className="absolute right-4">
<Icon path={mdiArrowRight} color="white" size={1} />
</div>
</button>
</div>
</div>
</main>
</>
);
}