Skip to content

Commit 1ca8b76

Browse files
feat: integrate CalendarHeatmap component for visualizing LeetCode submission data
1 parent 78f633b commit 1ca8b76

File tree

4 files changed

+87
-13
lines changed

4 files changed

+87
-13
lines changed

app/dashboard/page.tsx

+31-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import Link from "next/link";
66
import { useLeetcodeStore } from "@/store/LeetcodeStore/useLeetcodeStore";
77
import { Card, CardContent, CardHeader } from "@/components/ui/card";
88
import { Skeleton } from "@/components/ui/skeleton";
9-
import { Line, Bar, Doughnut } from "react-chartjs-2";
9+
import { Doughnut } from "react-chartjs-2";
10+
11+
import CalendarHeatmap from "react-calendar-heatmap";
12+
import "../styles/style.css";
13+
import 'react-calendar-heatmap/dist/styles.css';
14+
1015
import {
1116
Chart as ChartJS,
1217
CategoryScale,
@@ -82,6 +87,17 @@ export default function Dashboard() {
8287
}],
8388
};
8489

90+
91+
const processLeetCodeData = (submissionCalendar: string) => {
92+
const parsedData = JSON.parse(submissionCalendar);
93+
94+
return Object.entries(parsedData).map(([timestamp]) => ({
95+
date: new Date(Number(timestamp) * 1000).toISOString().split("T")[0]
96+
}));
97+
};
98+
99+
console.log(processLeetCodeData(userDetails.submissionCalendar));
100+
85101
return (
86102
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 space-y-8">
87103
{/* Profile Header Card */}
@@ -147,16 +163,21 @@ export default function Dashboard() {
147163
</span>
148164
</div>
149165
</CardHeader>
150-
<CardContent className="p-6">
151-
<LeetCodeCalendar
152-
username="yashksaini"
153-
blockSize={11}
154-
blockMargin={3}
155-
fontSize={11}
156-
theme={exampleTheme}
157-
style={{ maxWidth: '100%' }}
166+
<CardContent className="p-6">
167+
<CalendarHeatmap
168+
values={processLeetCodeData(userDetails.submissionCalendar)}
169+
startDate={new Date(new Date().setFullYear(new Date().getFullYear() - 1))}
170+
endDate={new Date()}
171+
classForValue={(value) => {
172+
if (!value) {
173+
return 'color-empty';
174+
}
175+
return `color-scale-${(value.count),4}`;
176+
}}
177+
showWeekdayLabels
178+
onMouseOver={(e, value) => console.log(e, value)}
158179
/>
159-
</CardContent>
180+
</CardContent>
160181
</Card>
161182

162183
{/* Recent Submissions Card */}

app/styles/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.react-calendar-heatmap .color-scale-1 { fill: #d6e685; }
2+
.react-calendar-heatmap .color-scale-2 { fill: #8cc665; }
3+
.react-calendar-heatmap .color-scale-3 { fill: #44a340; }
4+
.react-calendar-heatmap .color-scale-4 { fill: #1e6823; }

package-lock.json

+49-3
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
@@ -10,6 +10,7 @@
1010
"postinstall": "prisma generate"
1111
},
1212
"dependencies": {
13+
"@babel/runtime": "^7.22.5",
1314
"@hookform/resolvers": "^3.10.0",
1415
"@prisma/client": "^6.2.1",
1516
"@radix-ui/react-accordion": "^1.2.2",
@@ -27,6 +28,7 @@
2728
"@radix-ui/react-tooltip": "^1.1.6",
2829
"@supabase/ssr": "^0.5.2",
2930
"@types/bcryptjs": "^2.4.6",
31+
"@types/react-calendar-heatmap": "^1.9.0",
3032
"@types/react-chartjs-2": "^2.0.2",
3133
"axios": "^1.7.9",
3234
"bcryptjs": "^2.4.3",
@@ -44,6 +46,7 @@
4446
"motion": "^11.18.2",
4547
"next": "15.1.2",
4648
"react": "^18.3.1",
49+
"react-calendar-heatmap": "^1.9.0",
4750
"react-chartjs-2": "^5.3.0",
4851
"react-dom": "^18.3.1",
4952
"react-hook-form": "^7.54.2",

0 commit comments

Comments
 (0)