import { useState, useEffect } from 'react' import styles from './TerminalHeader.module.css' import { PROJECT_NAME, REPO_NAME, LINKS, AUTHORS } from '../config' function useGitHubProfile(username) { const [profile, setProfile] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { const cacheKey = 'gh-profile-' + username // Check sessionStorage first — avoids hammering the API on every render try { const cached = sessionStorage.getItem(cacheKey) if (cached) { setProfile(JSON.parse(cached)) setLoading(false) return } } catch (e) {} fetch('https://api.github.com/users/' + username) .then(r => { if (!r.ok) throw new Error('HTTP ' + r.status) return r.json() }) .then(d => { // Don't cache error responses like rate limit messages if (!d.message) { try { sessionStorage.setItem(cacheKey, JSON.stringify(d)) } catch (e) {} } setProfile(d) setLoading(false) }) .catch(() => setLoading(false)) }, [username]) return { profile, loading } } function AuthorTile({ username, active }) { const { profile, loading } = useGitHubProfile(username) const tileClass = styles.authorTile + (active ? ' ' + styles.authorTileActive : '') if (loading) { return (
) } if (!profile || profile.message) { return (
{username} @{username}
) } return ( {profile.login}
{profile.name || profile.login} @{profile.login} {profile.bio ? {profile.bio} :
}
) } function AuthorsTiles() { const [active, setActive] = useState(0) useEffect(() => { if (AUTHORS.length <= 1) return const t = setInterval(() => { setActive(i => (i + 1) % AUTHORS.length) }, 4000) return () => clearInterval(t) }, []) return (
› Authors:
{AUTHORS.map((username, i) => ( ))}
) } export default function TerminalHeader() { return (
javadoc-index — bash

{PROJECT_NAME}

$ browse-docs {REPO_NAME} --all-versions
› Fetching available documentation builds...
› Found project links:
{LINKS.map(function(l) { return ( {l.tag} {l.label} ↗ ) })}
$
) }