johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
<script lang="ts">
import type * as getActorActivity from '#lib/lexicons/dev/knotless/getActorActivity.ts';
import { plural } from '#lib/format.ts';
import { weekly, weekOf, YEAR } from '#lib/activity.ts';
/** How much an account did each week of the year to `today`, as a row of bars, each saying what it holds on hover. */
let { days, today }: { days: getActorActivity.DayView[]; today: string } = $props();
const kinds = [
['pushes', 'push', 'pushes'],
['pulls', 'pull', 'pulls'],
['issues', 'issue', 'issues'],
['comments', 'comment', 'comments'],
['repos', 'repository', 'repositories']
] as const;
const each = $derived(kinds.map(([k]) => weekly(days, today, YEAR, (d) => d[k] ?? 0)));
const weeks = $derived(
each[0].map((_, i) => {
const counts = kinds
.map(([, one, many], k) => [each[k][i], one, many] as const)
.filter(([n]) => n > 0);
const total = counts.reduce((sum, [n]) => sum + n, 0);
const said = counts.map(([n, one, many]) => plural(n, one, many)).join(', ');
return { total, title: `Week of ${weekOf(today, YEAR, i)}: ${said || 'nothing'}` };
})
);
const most = $derived(Math.max(1, ...weeks.map((w) => w.total)));
const active = $derived(weeks.filter((w) => w.total > 0).length);
</script>
<section class="strip">
<div class="section">
<h2>This year</h2>
<span class="mute">{`active in ${active} of the last ${YEAR} weeks`}</span>
</div>
<div class="weeks" role="img" aria-label="What was done each week, the last {YEAR} weeks">
{#each weeks as w, i (i)}<span
class:none={!w.total}
style:height="{(w.total / most) * 100}%"
title={w.title}
></span>{/each}
</div>
<div class="ends"><span>A year ago</span><span>This week</span></div>
</section>