From 6fe3859ca127ff7bb1ff660ce175d10e495b1b84 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Tue, 21 Oct 2025 22:19:08 +0200 Subject: [PATCH] A few things here and there --- src/app/api/contribs/route.ts | 34 ++++++++++++++++++++++++++++++++++ src/app/layout.tsx | 8 +------- src/app/page.tsx | 34 ++++++++++++++++++++++++++-------- src/components/PinnedRepos.tsx | 2 +- src/components/Skill.tsx | 3 +-- 5 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 src/app/api/contribs/route.ts diff --git a/src/app/api/contribs/route.ts b/src/app/api/contribs/route.ts new file mode 100644 index 0000000..a107556 --- /dev/null +++ b/src/app/api/contribs/route.ts @@ -0,0 +1,34 @@ +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest) { + const username = "kleo-dev"; + const token = process.env.GITHUB_TOKEN; + + const query = ` + query { + user(login: "${username}") { + contributionsCollection { + contributionCalendar { + totalContributions + } + } + } + } + `; + + const response = await fetch("https://api.github.com/graphql", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ query }), + }); + + const data = await response.json(); + const total = + data.data.user.contributionsCollection.contributionCalendar + .totalContributions; + + return NextResponse.json({ total }, { status: 200 }); +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 0667b63..3c5b57c 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -15,13 +15,7 @@ export default function RootLayout({ }>) { return ( - - {/* */} - {/*
*/} - {children} - {/*
*/} - {/*
*/} - + {children} ); } diff --git a/src/app/page.tsx b/src/app/page.tsx index b4a8f3e..7e683db 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,3 +1,5 @@ +"use client"; + import PinnedRepos from "@/components/PinnedRepos"; import Skill from "@/components/Skill"; import { @@ -12,9 +14,22 @@ import { } from "@fortawesome/free-brands-svg-icons"; import { faJava } from "@fortawesome/free-brands-svg-icons/faJava"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useEffect, useState } from "react"; import GitHubCalendar from "react-github-calendar"; export default function App() { + const [contribs, setContribs] = useState(); + + useEffect(() => { + const fetchContributions = async () => { + const res = await fetch("/api/contribs"); + const data = await res.json(); + console.log("Total contributions:", data.total); + setContribs(data.total || undefined); + }; + fetchContributions(); + }, []); + return (
@@ -35,8 +50,7 @@ export default function App() { - +
@@ -75,7 +90,10 @@ export default function App() {
-
+

+ {contribs || "Loading.."} contributions in the last year +

+
diff --git a/src/components/Skill.tsx b/src/components/Skill.tsx index 84f8cfc..de9fc89 100644 --- a/src/components/Skill.tsx +++ b/src/components/Skill.tsx @@ -22,8 +22,7 @@ export default function Skill({
);