Skip to content

Commit

Permalink
style: continuation of quiz attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoEscaleira committed Feb 23, 2024
1 parent 1309e98 commit f5d76fa
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions src/components/AttemptHistoryTable/AttemptHistoryTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect } from "react";
import { useLazyQuery } from "@apollo/client";
import { Typography } from "@material-tailwind/react";
import { differenceInMinutes, differenceInSeconds } from "date-fns";
import { Loader2 } from "lucide-react";
import { Button, Typography } from "@material-tailwind/react";
import { ChevronRight, Loader2 } from "lucide-react";
import { ScoreChip } from "@components/ScoreChip/ScoreChip.tsx";
import { useUserStore } from "@state/userStore.ts";
import { GET_QUIZ_ATTEMPTS } from "@utils/queries/QuizAttempts.ts";

Expand All @@ -22,23 +22,28 @@ export function AttemptHistoryTable({ quizId }: QuizAttemptProps) {

if (!userId) return null;

console.log(data);

return (
<div className="flex w-full flex-col">
<Typography className="font-medium">Attempt History</Typography>
<section className="flex items-center justify-between">
<Typography variant="h2" className="text-xl font-medium">
Attempt History
</Typography>
<Button variant="outlined" color="deep-orange" size="sm">
View All
</Button>
</section>
{loading ? (
<Loader2 size={20} className="mt-4 animate-spin" />
) : (
<div className="mt-4">
{data?.attempts.map(({ id, correctOptions, startTime, endTime, quiz: { questions } }) => {
const percentage = (correctOptions / questions.length) * 100;
const minutes = differenceInMinutes(new Date(endTime), new Date(startTime));
const seconds = differenceInSeconds(new Date(endTime), new Date(startTime));

<div className="mt-4 flex flex-col gap-2">
{data?.attempts.map(({ id, percentage, minutes, seconds }, index) => {
return (
<div key={id} className="">
{percentage}% - took {minutes} minutes and {seconds} seconds
<div key={id} className="flex items-center">
<Typography className="mr-2 text-lg font-medium">{index + 1}.</Typography>
<ScoreChip percentage={percentage} /> <ChevronRight className="mx-2 size-6" />
<Typography className="">
{minutes}m : {seconds}s
</Typography>
</div>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuizAttempt/QuizAttempt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function QuizAttempt({ quiz }: QuizAttemptProps) {
<>
<Button
variant="gradient"
className="mt-10"
className="mt-6"
color="green"
fullWidth
onClick={() => {
Expand Down
Loading

0 comments on commit f5d76fa

Please sign in to comment.