Skip to content

Commit ad0bec2

Browse files
feat: add LeetCode progress chart and profile page
1 parent ff2c1fa commit ad0bec2

File tree

5 files changed

+126
-9
lines changed

5 files changed

+126
-9
lines changed

app/dashboard/page.tsx

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"use client";
22

3-
import { useEffect } from "react";
3+
import { useEffect, useState } from "react";
44
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
55
import { Skeleton } from "@/components/ui/skeleton";
66
import { useAuthStore } from "@/store/AuthStore/useAuthStore";
77
import DashboardNavbar from "@/components/dashboardComponents/DashboardNavbar";
88
import { DashboardContentSkeleton } from "@/components/dashboardComponents/DashboardContentSkeleton";
9+
import { Bar } from "react-chartjs-2";
10+
import { Chart as ChartJS, CategoryScale, LinearScale, BarElement } from "chart.js";
11+
12+
ChartJS.register(CategoryScale, LinearScale, BarElement);
913

1014
function DashboardContent({ authUser }: any) {
1115
return (
@@ -25,7 +29,7 @@ function DashboardContent({ authUser }: any) {
2529
</p>
2630
</CardContent>
2731
</Card>
28-
32+
{/*
2933
<Card>
3034
<CardHeader>
3135
<CardTitle>LeetCode Stats</CardTitle>
@@ -35,24 +39,65 @@ function DashboardContent({ authUser }: any) {
3539
LeetCode stats are coming soon!
3640
</p>
3741
</CardContent>
38-
</Card>
42+
</Card> */}
3943
</main>
4044
);
4145
}
4246

4347
export default function Dashboard() {
4448
const { authUser, fetchAuthUser, authUserLoading } = useAuthStore();
49+
const [leetcodeStats, setLeetcodeStats] = useState<any>(null);
4550

4651
useEffect(() => {
4752
fetchAuthUser();
4853
}, [fetchAuthUser]);
54+
55+
// Fetch and store stats once we have the user
56+
useEffect(() => {
57+
if (authUser?.leetcodeUsername && authUser?.id) {
58+
const fetchStats = async () => {
59+
const res = await fetch(
60+
`/api/leetcode?username=${authUser.leetcodeUsername}&id=${authUser.id}`,
61+
{ method: "POST" }
62+
);
63+
if (res.ok) {
64+
const data = await res.json();
65+
setLeetcodeStats(data.stats);
66+
}
67+
};
68+
fetchStats();
69+
}
70+
}, [authUser]);
71+
72+
// Simple bar chart config
73+
const chartData = {
74+
labels: ["Easy", "Medium", "Hard"],
75+
datasets: [
76+
{
77+
label: "Solved",
78+
data: leetcodeStats?.submitStats.acSubmissionNum?.map((i: any) => i.count) || [0, 0, 0],
79+
backgroundColor: ["#4ade80", "#fbbf24", "#ef4444"],
80+
},
81+
],
82+
};
83+
4984
return (
5085
<div className="min-h-screen w-full">
5186
<DashboardNavbar isLoading={authUserLoading} userId={authUser?.id} />
5287
{authUserLoading ? (
5388
<DashboardContentSkeleton />
5489
) : (
55-
<DashboardContent authUser={authUser} />
90+
<>
91+
<DashboardContent authUser={authUser} />
92+
{leetcodeStats && (
93+
<div className="container mx-auto mt-6">
94+
<h2 className="text-xl font-semibold mb-4">Your LeetCode Progress</h2>
95+
<div className="max-w-xl">
96+
<Bar data={chartData} />
97+
</div>
98+
</div>
99+
)}
100+
</>
56101
)}
57102
</div>
58103
);

app/dashboard/profile/page.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
const ProfilePage: React.FC = () => {
4+
return (
5+
<div>
6+
<h1>Profile Page</h1>
7+
<p>Welcome to your profile!</p>
8+
</div>
9+
);
10+
};
11+
12+
export default ProfilePage;

components/dashboardComponents/AppSidebar.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import {
44
Calendar,
5+
LayoutDashboard,
56
ChevronUp,
67
Search,
78
Settings,
@@ -30,19 +31,18 @@ import {
3031
} from "@/components/ui/dropdown-menu";
3132
import { cn } from "@/lib/utils";
3233
import { signout } from "@/app/actions/action";
33-
import Dashboard from "@/app/dashboard/page";
3434

3535
// Menu items.
3636
const items = [
3737
{
3838
title: "profile",
39-
url: "#",
39+
url: "/dashboard/profile",
4040
icon: User,
4141
},
4242
{
4343
title: "Problems",
4444
url: "#",
45-
icon: Dashboard,
45+
icon: LayoutDashboard,
4646
},
4747
{
4848
title: "Calendar",

package-lock.json

+59-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
"@radix-ui/react-tooltip": "^1.1.6",
2424
"@supabase/ssr": "^0.5.2",
2525
"@types/bcryptjs": "^2.4.6",
26+
"@types/react-chartjs-2": "^2.0.2",
2627
"axios": "^1.7.9",
2728
"bcryptjs": "^2.4.3",
29+
"chart.js": "^4.4.7",
2830
"class-variance-authority": "^0.7.1",
2931
"clsx": "^2.1.1",
3032
"embla-carousel-react": "^8.5.1",
@@ -33,6 +35,7 @@
3335
"motion": "^11.17.0",
3436
"next": "15.1.2",
3537
"react": "^19.0.0",
38+
"react-chartjs-2": "^5.3.0",
3639
"react-dom": "^19.0.0",
3740
"react-hook-form": "^7.54.2",
3841
"tailwind-merge": "^2.6.0",

0 commit comments

Comments
 (0)