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 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 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
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
2 changes: 1 addition & 1 deletion client/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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
25 changes: 25 additions & 0 deletions client/src/components/ui/Competition/competition.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";

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

function Competition() {
return (
<>
<h1 className="text-center">Past Questions and Solutions</h1>
<div className="flex flex-col items-center gap-5">
<Button className="h-[66px] w-[998px] rounded-[5px] border-[1.5px] border-black bg-[#FFE8A3] text-[22px]">
Competition Name (e.g 2024)
</Button>
<Button>Competition Name (e.g 2024)</Button>
<Button>Competition Name (e.g 2024)</Button>
</div>
<h1 className="text-center">Practice Test</h1>
<div className="flex flex-col items-center gap-4">
<Button>Practice Test Name (e.g.WAJO Practice Test A)</Button>
<Button>Practice Test Name (e.g.WAJO Practice Test A)</Button>
</div>
</>
);
}

export default Competition;
10 changes: 4 additions & 6 deletions client/src/components/ui/Question/data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down Expand Up @@ -90,10 +90,10 @@ export function Datagrid({
</TableHead>
<TableHead className="w-1/4">
<div className="flex items-center text-white">
<span>Category</span>
<span>Genre</span>
<span
className="ml-2 cursor-pointer"
onClick={() => sortByColumn("category")}
onClick={() => sortByColumn("genre")}
>
<svg
width="10"
Expand Down Expand Up @@ -138,9 +138,7 @@ export function Datagrid({
className={"divide-gray-200 border-gray-50 text-sm text-black"}
>
<TableCell className="w-1/4">{item.name || "\u00A0"}</TableCell>
<TableCell className="w-1/4">
{item.category || "\u00A0"}
</TableCell>
<TableCell className="w-1/4">{item.genre || "\u00A0"}</TableCell>
<TableCell className="w-1/4">
{item.difficulty || "\u00A0"}
</TableCell>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Test/competition-data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { SortIcon } from "@/components/ui/icon";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Test/insight-data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";

import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Test/leaderboard-data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Test/practice-data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Test/ranking-data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";

import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Users/data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ui/Users/school-data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/ui/Users/team-data-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";

import { Button } from "@/components/ui/button";
import { Pagination } from "@/components/ui/pagination";
import Pagination from "@/components/ui/pagination";
import {
Table,
TableBody,
Expand Down Expand Up @@ -114,7 +114,7 @@ export function TeamDataGrid({
<Pagination
totalPages={totalPages}
currentPage={currentPage}
onPageChange={(page) => handlePageChange(page)}
onPageChange={(page: number) => handlePageChange(page)}
className="mr-20 mt-5 flex justify-end"
/>
</div>
Expand Down
20 changes: 20 additions & 0 deletions client/src/components/ui/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;
73 changes: 73 additions & 0 deletions client/src/components/ui/buttonList.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in style-guide.md

Folders should use PascalCase while files should use kebab-case.

Please update the file name to: button-list.tsx

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The totalQuestions prop is not being used, consider used it instead of a fixed number.

}) => {
const [startIndex, setStartIndex] = useState(0);
const [endIndex, setEndIndex] = useState(10);
const buttonsPerPage = 10;

const updateIndexes = () => {
// if (currentPage > endIndex) {
// setStartIndex(currentPage - 1);
// setEndIndex(currentPage + 9);
// } else if (currentPage < startIndex) {
// setStartIndex(currentPage - 1);
// setEndIndex(currentPage + 9);
// }
if (startIndex === 0) {
if (currentPage < 10) {
setStartIndex(0);
setEndIndex(10);
} else if (currentPage >= 10) {
setStartIndex(6);
setEndIndex(16);
}
} else if (currentPage === 7) {
setStartIndex(0);
setEndIndex(10);
}
};
Comment on lines +18 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentPage logic is static now. Consider making it dynamic to handle cases like 21 questions. Additionally, buttonsPerPage is a great feature for limiting questions in this case, but is currently declared and unused.


const handleClick = (num: number) => {
setCurrentPage(num);
updateIndexes();

console.log(startIndex);
console.log(endIndex);
};

useEffect(() => {
updateIndexes();
}, [currentPage]);

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

export default ButtonList;
28 changes: 28 additions & 0 deletions client/src/components/ui/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