-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
"use client"; | ||
|
||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@/components/ui/table"; | ||
import Link from "next/link"; | ||
|
||
interface Answer { | ||
questionNumber: number; | ||
question: string; | ||
answer: string; | ||
} | ||
|
||
type TemplateDataItem = { | ||
question: string; | ||
answer: string; | ||
}; | ||
|
||
type QuizHistoryItem = { | ||
time: number; | ||
name: string; | ||
answers: Answer[]; | ||
templateData: TemplateDataItem[]; | ||
correctCount: number; | ||
}; | ||
|
||
export function HistoryList() { | ||
const quizHistory = JSON.parse(localStorage?.getItem("quizHistory") || "[]"); | ||
|
||
return ( | ||
<main className="flex flex-1 flex-col gap-4 p-4 lg:gap-6 lg:p-6"> | ||
{quizHistory.length <= 0 ? ( | ||
<div | ||
className="flex flex-1 items-center justify-center rounded-lg border border-dashed shadow-sm" | ||
x-chunk="history-chunk-1" | ||
> | ||
<div className="flex flex-col items-center gap-1 text-center"> | ||
<h3 className="text-2xl font-bold tracking-tight"> | ||
You have no exam history | ||
</h3> | ||
<p className="text-sm text-muted-foreground"> | ||
You can take an exam at the{" "} | ||
<Link | ||
className="font-bold transition-colors hover:text-foreground/80" | ||
href="/" | ||
> | ||
Home | ||
</Link>{" "} | ||
tab. | ||
</p> | ||
</div> | ||
</div> | ||
) : ( | ||
<div | ||
className="flex flex-1 items-start justify-center rounded-lg border border-solid shadow-sm md:py-6" | ||
x-chunk="history-chunk-1" | ||
> | ||
<div className="flex flex-col items-center gap-1 text-center"> | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Name</TableHead> | ||
<TableHead>Results</TableHead> | ||
<TableHead className="hidden md:table-cell"> | ||
Created at | ||
</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{quizHistory.map( | ||
(quizHistoryItem: QuizHistoryItem, index: number) => ( | ||
<TableRow key={index}> | ||
<TableCell className="font-medium"> | ||
{quizHistoryItem.name} | ||
</TableCell> | ||
<TableCell className="font-medium"> | ||
{quizHistoryItem.correctCount}/ | ||
{quizHistoryItem.templateData.length} ( | ||
{( | ||
(quizHistoryItem.correctCount / | ||
quizHistoryItem.templateData.length) * | ||
100 | ||
).toFixed(2)} | ||
%) | ||
</TableCell> | ||
<TableCell className="hidden md:table-cell"> | ||
{new Date(quizHistoryItem.time).toLocaleString()} | ||
</TableCell> | ||
</TableRow> | ||
) | ||
)} | ||
</TableBody> | ||
</Table> | ||
</div> | ||
</div> | ||
)} | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters