import { Link } from "@tanstack/react-router"; import { Avatar } from "~/ui/Avatar"; import { Panel } from "~/ui/Panel"; import { cn } from "~/utils/cn"; import type { getRepoInsights } from "~/fns/insights"; type Insights = Awaited>; const DAYS_PER_WEEK = 7; const WEEK_MS = DAYS_PER_WEEK * 24 * 60 * 60 * 1000; const MONTH_FORMAT = new Intl.DateTimeFormat(undefined, { month: "short", timeZone: "UTC" }); const WEEK_FORMAT = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", timeZone: "UTC" }); const PULSE_ITEMS = [ { key: "pullsMerged", label: "Pull requests merged" }, { key: "pullsOpened", label: "Pull requests opened" }, { key: "issuesClosed", label: "Issues closed" }, { key: "issuesOpened", label: "Issues opened" }, { key: "activeAuthors", label: "Active authors" }, ] as const; export function PulseStats({ pulse }: { pulse: Insights["pulse"] }) { return (
{PULSE_ITEMS.map((item) => (
{item.label}
{pulse[item.key]}
))}
); } function Bars({ values, weekStart, className }: { values: number[]; weekStart: number; className?: string }) { const peak = Math.max(1, ...values); const total = values.reduce((sum, value) => sum + value, 0); return (
{total} commits over {values.length} weeks, peaking at {peak} in one week {values.map((value, week) => { const start = weekStart + week * WEEK_MS; const label = `${value} ${value === 1 ? "commit" : "commits"}, week of ${WEEK_FORMAT.format(start)}`; return (
0 ? "bg-accent-500 hover:bg-accent-400" : "bg-kumo-base")} style={{ height: `${Math.max(4, (value / peak) * 100)}%` }} /> ); })}
); } export function CommitActivity({ insights }: { insights: Insights }) { const total = insights.weekly.reduce((sum, value) => sum + value, 0); const months = insights.weekly.flatMap((_, week) => { const start = new Date(insights.weekStart + week * WEEK_MS); return start.getUTCDate() <= DAYS_PER_WEEK ? [{ week, label: MONTH_FORMAT.format(start) }] : []; }); return ( {total} {total === 1 ? "commit" : "commits"} on the default branch in the last year } >
{months.map((month) => ( {month.label} ))}
); } export function Contributors({ insights }: { insights: Insights }) { if (insights.contributors.length === 0) return null; return ( Last 52 weeks}>
    {insights.contributors.map((person, rank) => (
  1. {rank + 1}
    {person.account ? ( {person.account} ) : ( {person.name} )}

    {person.commits} {person.commits === 1 ? "commit" : "commits"}

    {person.weekly.length > 0 && ( )}
  2. ))}
); }