Large diffs are not rendered by default.

@@ -15,9 +15,37 @@ export default function Home(): JSX.Element {
<NavBar />
<div className="container mx-auto pt-2 text-center">
<h1>Dashboard</h1>
<Link href="/quiz">
<h2 className="cursor-pointer bg-indigo-700 text-gray-200">Quiz</h2>
</Link>

<div className="container flex flex-col mx-auto w-full items-center justify-center">
<ul className="flex flex-col">
<Link href="/quiz_all">
<li className="border-gray-400 flex flex-row mb-2">
<div className="shadow border select-none cursor-pointer bg-white dark:bg-gray-800 rounded-md flex flex-1 items-center p-4">
<div className="flex flex-col w-10 h-10 justify-center items-center mr-4">
<h2 className="cursor-pointer bg-indigo-700 px-2 text-gray-200">Quiz</h2>
</div>
<div className="flex-1 pl-1 md:mr-16">
<div className="font-medium dark:text-white">Yongliang</div>
<div className="text-gray-600 dark:text-gray-200 text-sm">Developer</div>
</div>
</div>
</li>
</Link>
<Link href="/forum">
<li className="border-gray-400 flex flex-row mb-2">
<div className="shadow border select-none cursor-pointer bg-white dark:bg-gray-800 rounded-md flex flex-1 items-center p-4">
<div className="flex flex-col w-10 h-10 justify-center items-center mr-4">
<h2 className="cursor-pointer bg-indigo-700 px-2 text-gray-200">Quiz</h2>
</div>
<div className="flex-1 pl-1 md:mr-16">
<div className="font-medium dark:text-white">Jun Xiong</div>
<div className="text-gray-600 dark:text-gray-200 text-sm">Developer</div>
</div>
</div>
</li>
</Link>
</ul>
</div>
<Footer />
</div>
</>
@@ -1,9 +1,13 @@
import { useState } from 'react'
import QuestionCard from '../components/quiz/QuestionCard'
import QuestionItem from '../components/quiz/QuestionItem'
import { fetchQuizQuestions } from '../components/quiz/API'
import { QuestionState } from '../components/quiz/API'
import Link from 'next/link'
import { hasSameContent } from '../components/common/Util'
import NavBar from '../components/common/NavBar'
import Head from 'next/head'
import Footer from '../components/common/Footer'
import Pagination from '../components/common/Pagination'

export type AnswerObject = {
question: string
@@ -67,41 +71,69 @@ export default function Quiz(): JSX.Element {

const previousQuestion = (): void => {
// move on to the previous question if not the last question
const nextQuestion = number - 1
if (nextQuestion === 0) {
const previousQuestion = number - 1
if (previousQuestion === -1) {
console.log('Cant')
return
} else {
setNumber(nextQuestion)
setNumber(previousQuestion)
}
}

return (
<div className="container mx-auto text-center flex flex-col">
<h1>Quiz</h1>
<Link href="/">Back</Link>
{gameOver || userAnswers.length === TOTAL_QUESTIONS ? (
<button className="start self-center bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={startQuiz}>
Start
</button>
) : null}
<div className="grid">
<NavBar />
<div className="container mx-auto pt-2 text-center">
<Head>
<title>View Selected Quiz</title>
<meta name="description" content="View Selected Quiz" />
<link rel="icon" href="/favicon.ico" />
</Head>
<div className="container mx-auto text-center flex flex-col items-center">
<h1 className="px-4 py-2 text-base font-bold">Quiz Title</h1>

{gameOver || userAnswers.length === TOTAL_QUESTIONS ? (
<div className="shadow-lg rounded-t-xl bg-blue-500 w-full md:w-64 p-6 dark:bg-gray-800">
<p className="text-white text-xl">Ready?</p>
<div className="mt-4">
<button
type="button"
className="py-2 px-4 bg-blue-700 hover:bg-blue-800 focus:ring-blue-500 focus:ring-offset-blue-200 text-white w-full transition ease-in duration-200 text-center text-base font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 rounded-lg "
onClick={startQuiz}
>
Start
</button>
<button
type="button"
className="py-2 px-4 mt-2 bg-blue-700 hover:bg-blue-800 focus:ring-blue-500 focus:ring-offset-blue-200 text-white w-full transition ease-in duration-200 text-center text-base font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 rounded-lg "
onClick={startQuiz}
>
<Link href="/quiz_all">Back To All Quizzes</Link>
</button>
</div>
</div>
) : null}

{!gameOver ? <p className="score">Score: {score}</p> : null}
{loading && <p>Loading Questions ...</p>}
{!loading && !gameOver && (
<QuestionCard
questionNumber={number + 1}
totalQuestions={TOTAL_QUESTIONS}
question={questions[number].question}
answers={questions[number].answers}
userAnswer={userAnswers ? userAnswers[number] : undefined}
callback={checkAnswer}
/>
)}
{!gameOver && !loading && number !== TOTAL_QUESTIONS - 1 ? (
<button className="next self-center bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={nextQuestion}>
Next Question
</button>
) : null}
{!gameOver ? <p className="score">Score: {score}</p> : null}
{loading && <p>Loading Questions ...</p>}
{!loading && !gameOver && (
<QuestionItem
questionNumber={number + 1}
totalQuestions={TOTAL_QUESTIONS}
question={questions[number].question}
answers={questions[number].answers}
userAnswer={userAnswers ? userAnswers[number] : undefined}
callback={checkAnswer}
/>
)}
{!gameOver && !loading ? (
<>
<Pagination numItem={TOTAL_QUESTIONS} onClickNext={nextQuestion} onClickPrevious={previousQuestion} />
</>
) : null}
</div>
</div>
<Footer />
</div>
)
}