diff --git a/src/components/GitHubGrid.jsx b/src/components/GitHubGrid.jsx index 75bd4f3..07ab4ed 100644 --- a/src/components/GitHubGrid.jsx +++ b/src/components/GitHubGrid.jsx @@ -11,7 +11,7 @@ export default function GitHubGrid() {
- A curated selection from my 38 repositories — 30 self-made and 8 + A curated selection from my 38 repositories — 27 self-made and 11 fully agentic projects built with AI agents, to develop a feel for system design and AI-assisted software development. The full list lives on{" "} diff --git a/src/components/LanguagePanel.jsx b/src/components/LanguagePanel.jsx index de60c6a..996acbb 100644 --- a/src/components/LanguagePanel.jsx +++ b/src/components/LanguagePanel.jsx @@ -1,12 +1,7 @@ import { useEffect, useState } from "react"; -import { profile } from "../content.js"; +import { languageStats } from "../content.js"; import { skillIcons } from "./skill-icons.js"; -const CACHE_KEY = "gh-lang-stats-v1"; -// 1h TTL: each refresh costs ~9 unauthenticated API calls (repo list + one /languages per repo), -// well inside the 60/hour limit. -const TTL_MS = 60 * 60 * 1000; - // GitHub /languages names → glyph keys in skill-icons.js const ICONS = { JavaScript: "JavaScript", @@ -39,135 +34,38 @@ function LangGlyph({ name }) { ); } -function readCache() { - try { - const raw = localStorage.getItem(CACHE_KEY); - if (!raw) return null; - const parsed = JSON.parse(raw); - return parsed && Array.isArray(parsed.rows) ? parsed : null; - } catch { - return null; - } -} - -function writeCache(rows, repoCount) { - try { - localStorage.setItem(CACHE_KEY, JSON.stringify({ at: Date.now(), rows, repoCount })); - } catch { - // storage unavailable — panel still works uncached - } -} - -async function fetchRows(githubUser) { - const reposRes = await fetch( - `https://api.github.com/users/${githubUser}/repos?per_page=100`, - { headers: { Accept: "application/vnd.github+json" } } - ); - if (!reposRes.ok) throw new Error("repo list failed"); - const repos = await reposRes.json(); - - const langResults = await Promise.allSettled( - repos.map((r) => - fetch(`https://api.github.com/repos/${githubUser}/${r.name}/languages`).then( - (res) => (res.ok ? res.json() : null) - ) - ) - ); - - const totals = {}; - for (const result of langResults) { - if (result.status === "fulfilled" && result.value) { - for (const [lang, bytes] of Object.entries(result.value)) { - totals[lang] = (totals[lang] || 0) + bytes; - } - } - } - - const total = Object.values(totals).reduce((a, b) => a + b, 0); - if (!total) throw new Error("no language data"); - - const rows = Object.entries(totals) - .map(([name, bytes]) => ({ name, pct: (bytes / total) * 100 })) - .filter((r) => r.pct >= 1) - .sort((a, b) => b.pct - a.pct) - .slice(0, 8); - - return { rows, repoCount: repos.length }; -} - export default function LanguagePanel() { - const [state, setState] = useState(() => { - const cached = readCache(); - if (cached) { - // Fresh or stale cache both render immediately; a refetch refreshes in the background. - return { status: "ready", rows: cached.rows, repoCount: cached.repoCount }; - } - return { status: "loading" }; - }); const [armed, setArmed] = useState(false); useEffect(() => { - let cancelled = false; - fetchRows(profile.githubUser) - .then(({ rows, repoCount }) => { - if (cancelled) return; - writeCache(rows, repoCount); - setState({ status: "ready", rows, repoCount }); - }) - .catch(() => { - if (cancelled) return; - const cached = readCache(); - if (cached) setState({ status: "ready", rows: cached.rows, repoCount: cached.repoCount }); - else setState({ status: "error" }); - }); - return () => { - cancelled = true; - }; - }, []); - - useEffect(() => { - if (state.status !== "ready") return; const frame = requestAnimationFrame(() => setArmed(true)); return () => cancelAnimationFrame(frame); - }, [state.status]); + }, []); return (
Crunching your GitHub repos…
- )} - - {state.status === "error" && ( -- Language stats are unavailable right now — they load live from GitHub. -
- )} - - {state.status === "ready" && - state.rows.map((row) => ( -