Skip to content

Commit f56085d

Browse files
Leaderboard + getting ready for deploy (#15)
* md preview * added markdown preview to create question. Changed to md preview from blocknote in update question. Fixed update question. * Fixed incorrect padding * Fixed initial markdown * added round enable functionality * put up same fonts in edit and update page * commented out navigation section on dashboard * Added template for LeaderBoard * Added template for LeaderBoard * created boilerplate leadboard * Added better syling for leaderboard * fixed build errors and bug fixes
1 parent 29bdcba commit f56085d

File tree

12 files changed

+573
-234
lines changed

12 files changed

+573
-234
lines changed

src/api/adminDashboard.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { handleAPIError } from "@/lib/error";
2+
import api from ".";
3+
import { generateSampleLeaderboard as generateSampleLeaderBoard } from "./sampleData";
4+
5+
export interface RoundParams {
6+
round_id: number;
7+
}
8+
9+
export interface LeaderBoardUser {
10+
ID: string;
11+
Name: string;
12+
Score: number | null;
13+
}
14+
15+
export async function RoundEnable(data: RoundParams) {
16+
try {
17+
const response = await api.post<{ message: string }>("/round/enable", data);
18+
return response.data;
19+
} catch (e) {
20+
console.log(e);
21+
throw handleAPIError(e);
22+
}
23+
}
24+
25+
export async function GetLeaderBoard() {
26+
try {
27+
const response = await api.get<LeaderBoardUser[]>("/leaderboard");
28+
return response.data
29+
.filter((user) => user.Score !== null) // Exclude users with null scores
30+
.sort((a, b) => b.Score! - a.Score!) // Sort by score in descending order
31+
.slice(0, 10); // Take the top 10
32+
33+
// return generateSampleLeaderBoard()
34+
// .filter((user) => user.Score !== null)
35+
// .sort((a, b) => b.Score! - a.Score!)
36+
// .slice(0, 10);
37+
38+
} catch (e) {
39+
throw handleAPIError(e);
40+
}
41+
}

src/api/interfaces.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export interface UpdateQuestionParams {
2+
id: string;
3+
description: string;
4+
title: string;
5+
input_format: string[];
6+
points: number;
7+
round: number;
8+
constraints: string[] ;
9+
output_format: string[];
10+
sample_test_input: string[];
11+
sample_test_output: string[];
12+
sample_explanation: string[];
13+
}
14+
15+
export interface QuestionResponse {
16+
ID: string;
17+
Description: string;
18+
Title: string;
19+
InputFormat: string[];
20+
Points: number;
21+
Round: number;
22+
Constraints: string[] | null;
23+
OutputFormat: string[];
24+
SampleTestInput: string[];
25+
SampleTestOutput: string[];
26+
Explanation: string[];
27+
}
28+
29+
export interface CreateQuestionParams {
30+
description: string,
31+
title: string,
32+
input_format: string[],
33+
points: number,
34+
round: number,
35+
constraints: string[],
36+
output_format: string[],
37+
sample_test_input: string[],
38+
sample_test_output: string[],
39+
sample_explanation: string[],
40+
}
41+
42+
43+
export interface DeleteQuestionResponse {
44+
message: string;
45+
}

src/api/questions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ interface DeleteQuestionResponse {
5454
// GET REQUEST
5555
export async function GetAllQuestions() {
5656
try {
57-
// const response = await api.get<QuestionResponse[]>("/questions");
58-
// return response.data;
59-
return generateSampleData()
57+
const response = await api.get<QuestionResponse[]>("/questions");
58+
return response.data;
59+
// return generateSampleData()
6060
} catch (e) {
6161
console.log(e);
6262
return [];

src/api/round.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/api/sampleData.ts

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,88 @@
1-
import {type QuestionResponse } from "./questions";
1+
import { LeaderBoardUser } from "./adminDashboard";
2+
import { type QuestionResponse } from "./questions";
23

34
const generateSampleData = (): QuestionResponse[] => {
4-
const sampleQuestions: QuestionResponse[] = [];
5-
6-
for (let i = 1; i <= 100; i++) {
7-
sampleQuestions.push({
8-
ID: `Q${i}`,
9-
Description: `Description for question ${i}. This question involves understanding the problem and providing a solution.`,
10-
Title: `Sample Question ${i}`,
11-
InputFormat: [`Input format for question ${i}.`],
12-
Points: Math.floor(Math.random() * 20) + 1, // Random points between 1 and 20
13-
Round: Math.floor(Math.random() * 3) + 1, // Random round between 1 and 3
14-
Constraints: [
15-
`Constraint 1 for question ${i}`,
16-
`Constraint 2 for question ${i}`,
17-
],
18-
OutputFormat: [`Output format for question ${i}.`],
19-
SampleTestInput: [`Sample input for question ${i}.`],
20-
SampleTestOutput: [`Expected output for question ${i}.`],
21-
Explanation: [
22-
`Explanation for the solution of question ${i}.`
23-
],
24-
});
25-
}
26-
27-
return sampleQuestions;
28-
};
5+
const sampleQuestions: QuestionResponse[] = [];
296

30-
export {generateSampleData};
7+
for (let i = 1; i <= 100; i++) {
8+
sampleQuestions.push({
9+
ID: `Q${i}`,
10+
Description: `Description for question ${i}. This question involves understanding the problem and providing a solution.`,
11+
Title: `Sample Question ${i}`,
12+
InputFormat: [`Input format for question ${i}.`],
13+
Points: Math.floor(Math.random() * 20) + 1, // Random points between 1 and 20
14+
Round: Math.floor(Math.random() * 3) + 1, // Random round between 1 and 3
15+
Constraints: [
16+
`Constraint 1 for question ${i}`,
17+
`Constraint 2 for question ${i}`,
18+
],
19+
OutputFormat: [`Output format for question ${i}.`],
20+
SampleTestInput: [`Sample input for question ${i}.`],
21+
SampleTestOutput: [`Expected output for question ${i}.`],
22+
Explanation: [`Explanation for the solution of question ${i}.`],
23+
});
24+
}
25+
26+
return sampleQuestions;
27+
};
28+
const generateSampleLeaderboard = (): LeaderBoardUser[] => {
29+
const students = [
30+
{
31+
ID: "01922f1a-0ff4-71b6-aee4-b6b69f41c4ce",
32+
Name: "Vedant Matanhelia",
33+
Score: 85,
34+
},
35+
{
36+
ID: "01922fc8-5e18-7c90-89ee-5f2f3e1012c8",
37+
Name: "abc",
38+
Score: 100000,
39+
},
40+
{
41+
ID: "01922f0d-010d-7d08-ad02-2383b0dbccff",
42+
Name: "Heet Jatania",
43+
Score: 88,
44+
},
45+
{
46+
ID: "01922f0d-9fe9-7534-8e63-712ca4fc226d",
47+
Name: "Vaibhav Jangid",
48+
Score: 80,
49+
},
50+
{
51+
ID: "01922f0e-0ff4-7d6e-964b-7c708d016d50",
52+
Name: "Yashita Puri",
53+
Score: 76,
54+
},
55+
{
56+
ID: "01922f0e-902b-7d1d-8773-a2007366c77d",
57+
Name: "Nishant Gupta",
58+
Score: 89,
59+
},
60+
{
61+
ID: "01922f0f-4fb1-7748-9d00-9465d66b989e",
62+
Name: "Prateek Srtivastava",
63+
Score: 81,
64+
},
65+
{
66+
ID: "01922f0f-a08a-7dec-8cb1-a6a0d0e94bb9",
67+
Name: "Samya Mehta",
68+
Score: 79,
69+
},
70+
{
71+
ID: "01922f10-0834-7a1f-aa11-fbb1ca143ced",
72+
Name: "Harshit",
73+
Score: 68,
74+
},
75+
{
76+
ID: "01922f25-e180-7d90-a7c7-aecbed743a73",
77+
Name: "Abhinav Pant",
78+
Score: null,
79+
},
80+
{
81+
ID: "01922f26-e68e-7672-a554-4c3085f050dc",
82+
Name: "Abhinav Ganeshan",
83+
Score: null,
84+
},
85+
];
86+
return students;
87+
};
88+
export { generateSampleData, generateSampleLeaderboard };
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { LeaderBoardUser } from "@/api/adminDashboard";
2+
import { DataTableColumnHeader } from "@/components/Table/DataTableColumnHeader";
3+
import { ColumnDef, createColumnHelper } from "@tanstack/react-table";
4+
5+
const columnHelper = createColumnHelper<LeaderBoardUser>();
6+
7+
export const LeaderBoardDataColumn = [
8+
// columnHelper.accessor("ID", {
9+
// header: ({ column }) => (
10+
// <DataTableColumnHeader column={column} title="Round" />
11+
// ),
12+
// enableSorting: true,
13+
// meta: {
14+
// className: "text-left",
15+
// displayName: "Round",
16+
// },
17+
// }),
18+
columnHelper.accessor("Name", {
19+
header: ({ column }) => (
20+
<DataTableColumnHeader column={column} title="Name" />
21+
),
22+
enableSorting: true,
23+
meta: {
24+
className: "text-center",
25+
displayName: "Name",
26+
},
27+
}),
28+
columnHelper.accessor("Score", {
29+
header: ({ column }) => (
30+
<DataTableColumnHeader column={column} title="Score" />
31+
),
32+
enableSorting: true,
33+
meta: {
34+
className: "text-center",
35+
displayName: "Score",
36+
},
37+
}),
38+
] as ColumnDef<LeaderBoardUser>[];

0 commit comments

Comments
 (0)