mirror of
https://github.com/mudabbir-ahmad/Portfolio_V1.git
synced 2026-12-06 19:53:09 +00:00
Add live GitHub push tracker between projects and repo grid
This commit is contained in:
1 parent
5a553fcab8
commit
be354a60c9
3 files changed
+258
No files matched your search
@@ -4,6 +4,7 @@ import Stats from "./components/Stats.jsx";
|
|||||||
import About from "./components/About.jsx";
|
import About from "./components/About.jsx";
|
||||||
import Experience from "./components/Experience.jsx";
|
import Experience from "./components/Experience.jsx";
|
||||||
import Projects from "./components/Projects.jsx";
|
import Projects from "./components/Projects.jsx";
|
||||||
|
import PushTracker from "./components/PushTracker.jsx";
|
||||||
import GitHubGrid from "./components/GitHubGrid.jsx";
|
import GitHubGrid from "./components/GitHubGrid.jsx";
|
||||||
import SkillsCarousel from "./components/SkillsCarousel.jsx";
|
import SkillsCarousel from "./components/SkillsCarousel.jsx";
|
||||||
import Interests from "./components/Interests.jsx";
|
import Interests from "./components/Interests.jsx";
|
||||||
@@ -20,6 +21,7 @@ export default function App() {
|
|||||||
<About />
|
<About />
|
||||||
<Experience />
|
<Experience />
|
||||||
<Projects />
|
<Projects />
|
||||||
|
<PushTracker />
|
||||||
<GitHubGrid />
|
<GitHubGrid />
|
||||||
<SkillsCarousel />
|
<SkillsCarousel />
|
||||||
<Interests />
|
<Interests />
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { profile } from "../content.js";
|
||||||
|
|
||||||
|
const WEEKS = 13;
|
||||||
|
const MAX_PAGES = 5;
|
||||||
|
|
||||||
|
function startOfLocalDay(d) {
|
||||||
|
const x = new Date(d);
|
||||||
|
x.setHours(0, 0, 0, 0);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDays(d, n) {
|
||||||
|
const x = new Date(d);
|
||||||
|
x.setDate(x.getDate() + n);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dayKey(d) {
|
||||||
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(
|
||||||
|
d.getDate()
|
||||||
|
).padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fmtDay(d) {
|
||||||
|
return d.toLocaleDateString("en-GB", { day: "numeric", month: "short" });
|
||||||
|
}
|
||||||
|
|
||||||
|
function levelFor(count) {
|
||||||
|
if (count <= 0) return 0;
|
||||||
|
if (count === 1) return 1;
|
||||||
|
if (count <= 3) return 2;
|
||||||
|
if (count <= 6) return 3;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchPushCounts(cutoff) {
|
||||||
|
const counts = new Map();
|
||||||
|
let totalPushes = 0;
|
||||||
|
let lastPush = null;
|
||||||
|
|
||||||
|
for (let page = 1; page <= MAX_PAGES; page++) {
|
||||||
|
const res = await fetch(
|
||||||
|
`https://api.github.com/users/${profile.githubUser}/events/public?per_page=100&page=${page}`,
|
||||||
|
{ headers: { Accept: "application/vnd.github+json" } }
|
||||||
|
);
|
||||||
|
if (!res.ok) throw new Error(`GitHub API responded ${res.status}`);
|
||||||
|
const events = await res.json();
|
||||||
|
if (!Array.isArray(events) || events.length === 0) break;
|
||||||
|
|
||||||
|
let oldest = null;
|
||||||
|
for (const ev of events) {
|
||||||
|
const created = new Date(ev.created_at);
|
||||||
|
oldest = oldest === null ? created : (created < oldest ? created : oldest);
|
||||||
|
if (ev.type !== "PushEvent") continue;
|
||||||
|
const day = startOfLocalDay(created);
|
||||||
|
if (day < cutoff) continue;
|
||||||
|
const k = dayKey(day);
|
||||||
|
counts.set(k, (counts.get(k) || 0) + 1);
|
||||||
|
totalPushes += 1;
|
||||||
|
if (lastPush === null || created > lastPush) lastPush = created;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Events arrive newest-first: once this page reaches past the window,
|
||||||
|
// older pages can't contribute anything.
|
||||||
|
if (oldest !== null && oldest < cutoff) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { counts, totalPushes, lastPush };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PushTracker() {
|
||||||
|
const [status, setStatus] = useState("loading");
|
||||||
|
const [data, setData] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const today = startOfLocalDay(new Date());
|
||||||
|
const thisSunday = addDays(today, -today.getDay());
|
||||||
|
const gridStart = addDays(thisSunday, -(WEEKS - 1) * 7);
|
||||||
|
const cutoff = addDays(gridStart, -5);
|
||||||
|
const result = await fetchPushCounts(cutoff);
|
||||||
|
if (cancelled) return;
|
||||||
|
setData({ ...result, today, gridStart });
|
||||||
|
setStatus("ready");
|
||||||
|
} catch {
|
||||||
|
if (!cancelled) setStatus("error");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
let grid = null;
|
||||||
|
let statsLine = null;
|
||||||
|
if (status === "ready" && data) {
|
||||||
|
const { counts, totalPushes, lastPush, today, gridStart } = data;
|
||||||
|
const activeDays = counts.size;
|
||||||
|
|
||||||
|
const columns = [];
|
||||||
|
for (let c = 0; c < WEEKS; c++) {
|
||||||
|
const week = [];
|
||||||
|
for (let r = 0; r < 7; r++) {
|
||||||
|
const day = addDays(gridStart, c * 7 + r);
|
||||||
|
const count = counts.get(dayKey(day)) || 0;
|
||||||
|
week.push({ day, count, future: day > today });
|
||||||
|
}
|
||||||
|
columns.push(week);
|
||||||
|
}
|
||||||
|
grid = columns;
|
||||||
|
|
||||||
|
statsLine = (
|
||||||
|
<p className="pt-stats">
|
||||||
|
{totalPushes} push{totalPushes === 1 ? "" : "es"} · {activeDays} active day
|
||||||
|
{activeDays === 1 ? "" : "s"}
|
||||||
|
{lastPush ? ` · last push ${fmtDay(lastPush)}` : ""}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="push-tracker section" id="activity">
|
||||||
|
<div className="container">
|
||||||
|
<p className="eyebrow">Activity</p>
|
||||||
|
<h2 className="section-title">Push tracker</h2>
|
||||||
|
<p className="section-lede">
|
||||||
|
Every git push across my public repositories, pulled live from GitHub's
|
||||||
|
events API — the last 13 weeks.
|
||||||
|
</p>
|
||||||
|
<div className="pt-card">
|
||||||
|
{status === "loading" && (
|
||||||
|
<p className="pt-note">Fetching push activity…</p>
|
||||||
|
)}
|
||||||
|
{status === "error" && (
|
||||||
|
<p className="pt-note">Push activity is unavailable right now.</p>
|
||||||
|
)}
|
||||||
|
{status === "ready" && grid && (
|
||||||
|
<>
|
||||||
|
<div className="pt-grid" role="img" aria-label="Push activity heatmap, last 13 weeks">
|
||||||
|
{grid.map((week, c) => (
|
||||||
|
<div className="pt-col" key={c}>
|
||||||
|
{week.map((cell, r) => (
|
||||||
|
<span
|
||||||
|
key={r}
|
||||||
|
className={`pt-cell l${cell.future ? 0 : levelFor(cell.count)}${cell.future ? " is-future" : ""}`}
|
||||||
|
title={
|
||||||
|
cell.future
|
||||||
|
? undefined
|
||||||
|
: `${fmtDay(cell.day)} — ${cell.count} push${cell.count === 1 ? "" : "es"}`
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="pt-foot">
|
||||||
|
{statsLine}
|
||||||
|
<div className="pt-legend" aria-hidden="true">
|
||||||
|
<span>less</span>
|
||||||
|
{[0, 1, 2, 3, 4].map((l) => (
|
||||||
|
<span className={`pt-cell l${l}`} key={l} />
|
||||||
|
))}
|
||||||
|
<span>more</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -583,6 +583,87 @@ a {
|
|||||||
background: var(--accent-tint);
|
background: var(--accent-tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- push tracker ---------- */
|
||||||
|
|
||||||
|
.push-tracker {
|
||||||
|
border-top: 1px solid var(--hairline);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-card {
|
||||||
|
margin-top: 48px;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--hairline);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
padding: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-grid {
|
||||||
|
display: flex;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-col {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-cell {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: #efede5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-cell.l1 {
|
||||||
|
background: #e0d6f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-cell.l2 {
|
||||||
|
background: #c6b2e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-cell.l3 {
|
||||||
|
background: #a184d6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-cell.l4 {
|
||||||
|
background: #7050bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-cell.is-future {
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-note {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 15px;
|
||||||
|
padding: 24px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-foot {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
margin-top: 18px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-stats {
|
||||||
|
color: var(--ink-soft);
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pt-legend {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------- github ---------- */
|
/* ---------- github ---------- */
|
||||||
|
|
||||||
.github {
|
.github {
|
||||||
|
|||||||
Reference in new issue
Block a user