Skip to content

Commit dc372ea

Browse files
itschetnamehul-m-prajapati
authored andcommitted
✨ Feat: Add GitHub metrics preview on user profile page (Fixes #50)
1 parent 1f47b7c commit dc372ea

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

src/components/MetricCard.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useState } from "react";
2+
3+
interface MetricCardProps {
4+
username: string;
5+
}
6+
7+
const MetricCard: React.FC<MetricCardProps> = ({ username }) => {
8+
const [loading, setLoading] = useState(true);
9+
10+
if (!username) return null;
11+
12+
const metricsURL = `https://metrics.lecoq.io/${username}`;
13+
14+
return (
15+
<div className="w-full flex flex-col items-center p-4">
16+
{loading && <p className="text-gray-500 mb-2">Loading metrics...</p>}
17+
<iframe
18+
src={metricsURL}
19+
width="100%"
20+
height="400"
21+
frameBorder="0"
22+
title="GitHub Metrics"
23+
className="rounded-lg shadow-md"
24+
onLoad={() => setLoading(false)}
25+
></iframe>
26+
</div>
27+
);
28+
};
29+
30+
export default MetricCard;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useParams } from "react-router-dom";
2+
import { useEffect, useState } from "react";
3+
import MetricCard from "../../components/MetricCard";
4+
5+
type PR = {
6+
title: string;
7+
html_url: string;
8+
repository_url: string;
9+
};
10+
11+
export default function UserProfile() {
12+
const { username } = useParams();
13+
const [profile, setProfile] = useState<any>(null);
14+
const [prs, setPRs] = useState<PR[]>([]);
15+
const [loading, setLoading] = useState(true);
16+
17+
useEffect(() => {
18+
async function fetchData() {
19+
if (!username) return;
20+
21+
const userRes = await fetch(`https://api.github.com/users/${username}`);
22+
const userData = await userRes.json();
23+
setProfile(userData);
24+
25+
const prsRes = await fetch(`https://api.github.com/search/issues?q=author:${username}+type:pr`);
26+
const prsData = await prsRes.json();
27+
setPRs(prsData.items);
28+
setLoading(false);
29+
}
30+
31+
fetchData();
32+
}, [username]);
33+
34+
if (loading) return <div className="text-center mt-10">Loading...</div>;
35+
36+
return (
37+
<div className="max-w-3xl mx-auto mt-10 p-4 bg-white shadow-xl rounded-xl">
38+
{profile && (
39+
<div className="text-center">
40+
<img src={profile.avatar_url} className="w-24 h-24 mx-auto rounded-full" />
41+
<h2 className="text-2xl font-bold mt-2">{profile.login}</h2>
42+
<p className="text-gray-600">{profile.bio}</p>
43+
</div>
44+
)}
45+
46+
{/* GitHub Metrics Preview */}
47+
<h3 className="text-xl font-semibold mt-6 mb-2">GitHub Metrics</h3>
48+
<MetricCard username={username || ""} />
49+
50+
51+
<h3 className="text-xl font-semibold mt-6 mb-2">Pull Requests</h3>
52+
<ul className="list-disc ml-6 space-y-2">
53+
{prs.map((pr, i) => (
54+
<li key={i}>
55+
<a href={pr.html_url} target="_blank" className="text-blue-600 hover:underline">
56+
{pr.title}
57+
</a>
58+
</li>
59+
))}
60+
</ul>
61+
</div>
62+
);
63+
}

0 commit comments

Comments
 (0)