Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 44 create quiz frontend #80

Open
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
83032be
skeleton quiz pages
AarifLamat Jan 7, 2025
bb05f21
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Jan 7, 2025
5443092
added lil headings
AarifLamat Jan 8, 2025
9b56c68
yellow bg is now yellow border
AarifLamat Jan 9, 2025
2e63f32
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Jan 9, 2025
5a1d074
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Jan 9, 2025
73c29fe
attempts at pagination
AarifLamat Jan 9, 2025
5d954e2
attempt at creating a quiz api
AarifLamat Jan 10, 2025
aa50eda
..comments
AarifLamat Jan 11, 2025
b66551a
create the competition folder and the file.
morepresent Jan 11, 2025
e55301f
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Jan 22, 2025
4f608ea
update psycopg
AarifLamat Jan 22, 2025
a04fb7e
Create components: ButtonList, CountDownDisplay, and SubmissionPopup.…
morepresent Jan 22, 2025
fb55341
Modify the buttonList.tsx, countdowndisplay and competition page.
morepresent Jan 22, 2025
51624b4
Merge branch 'main' into issue-44-Create_Quiz_Frontend
morepresent Jan 22, 2025
c7dfc42
Merge branch 'issue-44-Create_Quiz_Frontend' of https://github.com/co…
AarifLamat Jan 23, 2025
b642702
clarified api fetching logic and fixed some type errors
AarifLamat Jan 23, 2025
e51a703
type fix
AarifLamat Jan 23, 2025
8839ae5
more type error fixes
AarifLamat Jan 23, 2025
9d0a9c2
TYPE ERROR FIX!!
AarifLamat Jan 23, 2025
7badcda
fixed buttonList startIndex and endIndex not updating when clicking next
AarifLamat Jan 24, 2025
9ea8e9b
flake8 error fix
AarifLamat Jan 24, 2025
54c7e9c
update mock data fetching logic a lil
AarifLamat Jan 25, 2025
a2742dc
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Jan 25, 2025
3f52f89
fix
AarifLamat Jan 25, 2025
f88de48
fix migrations
AarifLamat Jan 25, 2025
9ea61f7
Modify the name of some components. Create the auto-saving component.
morepresent Jan 25, 2025
b9739f1
Modify the submission pop-up component so that clicking anywhere outs…
morepresent Jan 25, 2025
68510f7
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Jan 26, 2025
b9b771c
Merge branch 'issue-44-Create_Quiz_Frontend' of https://github.com/co…
AarifLamat Jan 26, 2025
b779516
fix linting errors
AarifLamat Jan 26, 2025
7c62775
fix
AarifLamat Jan 27, 2025
6c4c5fc
retrieved old migration files from an old commit
AarifLamat Jan 27, 2025
9952e1c
implemented suggestions from Lok
AarifLamat Jan 28, 2025
bdcb22d
Create a retrieve-questions component.
morepresent Feb 2, 2025
28e8683
Modify the retrieve-questions component.
morepresent Feb 3, 2025
ae4423f
create competition layout, organised components and made frontend con…
AarifLamat Feb 3, 2025
be387f7
moved retrieve questions
AarifLamat Feb 3, 2025
a1c0be8
made competition quizzes actually retrieve questions ahahaha
AarifLamat Feb 3, 2025
54f2b97
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Feb 5, 2025
bd39d9e
type fixes
AarifLamat Feb 5, 2025
93ccaf2
fixed type errors
AarifLamat Feb 5, 2025
b5a6130
updated auto saving feature and attempted to connect backend further
AarifLamat Feb 5, 2025
cd99264
fix empty upcomingCompetition bug
AarifLamat Feb 5, 2025
ee03f88
Add question result component and update quiz page structure
joshuachai Feb 8, 2025
fdbd8af
Merge branch 'issue-44-Create_Quiz_Frontend' of https://github.com/co…
AarifLamat Feb 11, 2025
05a1ff6
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Feb 11, 2025
210e504
fixed type errors
AarifLamat Feb 11, 2025
1291435
fixed some quiz fetching logic
AarifLamat Feb 11, 2025
5cf56b9
Merge branch 'main' into issue-44-Create_Quiz_Frontend
loklokyx Feb 12, 2025
f83e28a
code clean up
loklokyx Feb 12, 2025
d206822
fix(poetry): fix poetry lock content-hash
loklokyx Feb 12, 2025
089c285
Get the question_text, mark and image from the quizQuestionData. Rena…
morepresent Feb 12, 2025
510a0cc
Automaticaly submit the answer when countdown to 0. Modify the left t…
morepresent Feb 12, 2025
f7b7148
Include the image in the question. Modify the code in [id].tsx to ge…
morepresent Feb 13, 2025
983b048
feat(competition): add primary_id to JwtPayload, improve competition …
loklokyx Feb 14, 2025
27aafbf
chore(competition): code clean up
loklokyx Feb 14, 2025
32a193c
Merge branch 'main' into issue-44-Create_Quiz_Frontend
loklokyx Feb 14, 2025
be955fb
Display the startTime correctly.
morepresent Feb 15, 2025
881a90b
fix(quiz): rename user parameter to student in _get_slots_response me…
loklokyx Feb 15, 2025
19a44fe
fix(quiz): remove student parameter from quiz attempts endpoint and a…
loklokyx Feb 15, 2025
396e09d
feat(quiz): enhance image rendering and layout handling in GenericQui…
loklokyx Feb 15, 2025
8b5bd32
feat(quiz): add time_created field to Quiz model and update queryset …
yunho7687 Feb 15, 2025
1eaa02b
fix(quiz): update image URL handling and adjust layout for better res…
morepresent Feb 15, 2025
d23df2d
feat(quiz): add images field to QuestionSerializer for enhanced image…
yunho7687 Feb 15, 2025
b9555b2
Make the question image appear in the practice quiz
morepresent Feb 15, 2025
04f3f0d
feat(quiz): include quiz_attempt_id in CompetitionQuizViewSet respons…
yunho7687 Feb 15, 2025
3478668
fix(quiz): rename answer fields for consistency in GenericQuiz component
loklokyx Feb 15, 2025
7971cf2
feat(quiz): add quiz_attempt_id to CompetitionSlot interface
loklokyx Feb 15, 2025
8907e5f
Merge branch 'main' into issue-44-Create_Quiz_Frontend
loklokyx Feb 15, 2025
89c9b5a
fix(migrations)
loklokyx Feb 16, 2025
3b8054e
Merge branch 'main' of https://github.com/codersforcauses/wajo into i…
AarifLamat Feb 20, 2025
cdb5911
Merge branch 'issue-44-Create_Quiz_Frontend' of https://github.com/co…
AarifLamat Feb 20, 2025
209c18f
minor
AarifLamat Feb 20, 2025
7a28513
minor
AarifLamat Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function Navbar() {
<Button
variant={"outline"}
size={"lg"}
className="font-roboto border-2 border-black text-lg"
className="border-2 border-black font-roboto text-lg"
onClick={() => router.push("/dashboard")}
>
Dashboard
Expand All @@ -43,7 +43,7 @@ export default function Navbar() {
<Button
variant={"outline"}
size={"lg"}
className="font-roboto border-2 border-black text-lg"
className="border-2 border-black font-roboto text-lg"
>
Login
</Button>
Expand Down
67 changes: 67 additions & 0 deletions client/src/components/ui/Practice/question-result.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Check, X } from "lucide-react";
import React from "react";

import { cn } from "@/lib/utils";

interface QuestionResultProps {
question: string;
questionNumber: number;
answer: number;
correctAnswer: number;
solution: string;
marks: number;
}

export default function QuestionResult({
question,
questionNumber,
answer,
correctAnswer,
solution,
marks,
}: QuestionResultProps) {
const isCorrect = answer === correctAnswer;
return (
<div className="p-6">
<div>
<div className="item-end flex justify-between">
<h3>Question {questionNumber}</h3>
<span className="inline-block text-3xl">[{marks} mark]</span>
</div>
</div>
<div className="p-10">
<div>
<p>{question}</p>
</div>
<div className={isCorrect ? "bg-green-100" : "bg-red-300"}>
<h5 className="mb-5">Your Answer</h5>
<div className="flex items-center space-x-2">
<input
className={cn(
"border bg-white p-2 font-sans text-base",
isCorrect ? "border-green-500" : "border-red-500",
)}
type="text"
disabled
value={answer}
/>

{isCorrect ? (
<Check size={32} className="text-green-500" />
) : (
<X size={32} className="text-red-500" />
)}
</div>
</div>

<div>
<h5>Solution</h5>
<h5 className="p-2 font-sans text-base font-normal">
{correctAnswer}
</h5>
<p>{solution}</p>
</div>
</div>
</div>
);
}
20 changes: 20 additions & 0 deletions client/src/components/ui/Quiz/auto-saving.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";

interface Props {
answer: string;
setAnswer: (value: string) => void;
}

const AutoSavingAnswer: React.FC<Props> = ({ answer, setAnswer }) => {
return (
<input
type="text"
value={answer}
onChange={(e) => setAnswer(e.target.value)}
placeholder="Please input your answer"
className="mt-4 h-10 w-full min-w-64 rounded-sm border border-slate-500 px-2"
/>
);
};

export default AutoSavingAnswer;
67 changes: 67 additions & 0 deletions client/src/components/ui/Quiz/buttonList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";

interface ButtonListProps {
currentPage: number;
setCurrentPage: (page: number) => void;
totalQuestions: number;
}

const ButtonList: React.FC<ButtonListProps> = ({
currentPage,
setCurrentPage,
totalQuestions,
}) => {
const buttonsPerPage = 10;
const [startIndex, setStartIndex] = useState(0);
const [endIndex, setEndIndex] = useState(
Math.min(buttonsPerPage, totalQuestions),
);

useEffect(() => {
if (totalQuestions <= buttonsPerPage) {
// If totalQuestions is less than buttonsPerPage, just show all buttons
setStartIndex(0);
setEndIndex(totalQuestions);
return;
}

const halfButtons = Math.floor(buttonsPerPage / 2);

if (currentPage <= halfButtons) {
// When at the start of the list
setStartIndex(0);
setEndIndex(buttonsPerPage);
} else if (currentPage >= totalQuestions - halfButtons) {
// When at the end of the list
setStartIndex(totalQuestions - buttonsPerPage);
setEndIndex(totalQuestions);
} else {
// Normal pagination case
setStartIndex(currentPage - halfButtons);
setEndIndex(currentPage + halfButtons);
}
}, [currentPage, totalQuestions]);

return (
<div className="flex flex-wrap gap-1">
{Array.from({ length: endIndex - startIndex }, (_, i) => {
const pageNumber = startIndex + i + 1;
return (
<Button
key={pageNumber}
className="m-2"
variant={pageNumber === currentPage ? "default" : "outline"}
size="icon"
onClick={() => setCurrentPage(pageNumber)}
>
{pageNumber}
</Button>
);
})}
</div>
);
};

export default ButtonList;
28 changes: 28 additions & 0 deletions client/src/components/ui/Quiz/countdown-display.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";

interface CountdownDisplayProps {
timeLeft: number | null;
}

const formatTime = (timeLeft: number) => {
const hours = Math.floor(timeLeft / 3600);
const minutes = Math.floor((timeLeft - hours * 3600) / 60);
const secs = timeLeft % 60;
return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
};

const CountdownDisplay: React.FC<CountdownDisplayProps> = ({ timeLeft }) => {
return (
<div>
{timeLeft !== null ? (
<div className="rounded-full bg-green-500 px-6 py-2 text-lg font-semibold text-white shadow-md">
Time Left: {formatTime(timeLeft)}
</div>
) : (
<h2>Click "Start Quiz" to begin</h2>
)}
</div>
);
};

export default CountdownDisplay;
Loading