Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339<script lang="ts"> import { tick, type Component, type Snippet } from "svelte"; import type { Attachment } from "svelte/attachments"; import type { SvelteHTMLElements } from "svelte/elements"; import { SvelteDate } from "svelte/reactivity"; import { resolve } from "$app/paths"; import BookPlus from "$icon/book-plus"; import ChevronRight from "$icon/chevron-right"; import CircleDot from "$icon/circle-dot"; import GitCommit from "$icon/git-commit-horizontal"; import GitFork from "$icon/git-fork"; import GitPullRequest from "$icon/git-pull-request"; import Plus from "$icon/plus"; import Avatar from "#lib/components/ui/Avatar.svelte"; import Tag from "#lib/components/ui/Tag.svelte"; import ActivityTicket from "#lib/components/profile/ActivityTicket.svelte"; import { pluralize } from "#lib/format.ts"; import { groupByRepo, repoPath, type ActivityMetric } from "#lib/components/profile/profileActivityChart.ts"; import type { ActivityRepoRef, ProfileActivityMonth } from "#lib/components/profile/types.ts";
type Icon = Component<SvelteHTMLElements["svg"]>;
let { month, open, id, focus = null }: { month: ProfileActivityMonth | null; open: boolean; id: string; focus?: { metric: ActivityMetric } | null; } = $props();
const HEADER_REPOS = 3; const SHORT_SHA = 7; const SLIDE_DISTANCE = 12; const SLIDE_DURATION = 200;
let expanded = $state<Partial<Record<ActivityMetric, boolean>>>({}); let region = $state<HTMLElement>(); let previous: number | null = null;
const reduceMotion = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
$effect(() => { if (!focus) return; const { metric } = focus; expanded = { [metric]: true }; tick().then(async () => { const row = document.getElementById(`${id}-${metric}-row`); if (!region || !row) return; await Promise.allSettled( region.getAnimations({ subtree: true }).map((animation) => animation.finished) ); row.scrollIntoView({ block: "nearest", behavior: reduceMotion() ? "auto" : "smooth" }); }); });
const slideIn = (monthsAgo: number): Attachment<HTMLElement> => (node) => { if (previous !== null && previous !== monthsAgo) { const offset = reduceMotion() ? 0 : (monthsAgo < previous ? 1 : -1) * SLIDE_DISTANCE; node.animate( [ { opacity: 0, translate: `${offset}px 0` }, { opacity: 1, translate: "0 0" } ], { duration: SLIDE_DURATION, easing: getComputedStyle(node).getPropertyValue("--ease-out-strong") } ); } previous = monthsAgo; };
const title = (monthsAgo: number) => { const date = new SvelteDate(); date.setUTCDate(1); date.setUTCMonth(date.getUTCMonth() - monthsAgo); return new Intl.DateTimeFormat("en", { month: "long", year: "numeric", timeZone: "UTC" }).format(date); };
const repoHref = (repo: ActivityRepoRef) => resolve(repoPath(repo) as "/");
const tickets = $derived( month ? ([ { key: "issues", icon: CircleDot, count: pluralize(month.issues.length, "issue", "issues"), groups: groupByRepo(month.issues) }, { key: "pulls", icon: GitPullRequest, count: pluralize(month.pulls.length, "pull request", "pull requests"), groups: groupByRepo(month.pulls) } ] as const) : [] );</script>
{#snippet repoLabel(repo: ActivityRepoRef)} <Avatar did={repo.ownerDid} handle={repo.ownerHandle} size="mini" /> <span class="truncate">{repo.ownerHandle}/{repo.name}</span>{/snippet}
{#snippet repoTags(entries: { repo: ActivityRepoRef; count: number }[])} {#each entries.slice(0, HEADER_REPOS) as entry (repoPath(entry.repo))} <Tag truncate class="min-w-0 pl-3xs"> {@render repoLabel(entry.repo)} <span class="text-foreground-muted">{entry.count}</span> </Tag> {/each} {#if entries.length > HEADER_REPOS} <Tag color="muted">+{entries.length - HEADER_REPOS}</Tag> {/if}{/snippet}
{#snippet repoTerm(repo: ActivityRepoRef)} <dt class="min-w-0 py-3xs typography-paragraph-small"> <a href={repoHref(repo)} class="flex min-w-0 items-center gap-2xs text-foreground-muted hover:text-foreground-default" > {@render repoLabel(repo)} </a> </dt>{/snippet}
{#snippet row( key: ActivityMetric, icon: Icon, label: string, enabled: boolean, header: Snippet, body: Snippet)} {@const RowIcon = icon} {@const rowOpen = Boolean(expanded[key]) && enabled} <div id={`${id}-${key}-row`} class="scroll-my-sm rounded-md border border-border-default bg-background-default typography-paragraph-regular" > <button type="button" class="flex min-h-10 w-full items-center gap-sm px-sm py-xs text-left disabled:cursor-default" disabled={!enabled} aria-expanded={rowOpen} aria-controls={`${id}-${key}`} onclick={() => (expanded[key] = !expanded[key])} > <span class="flex shrink-0 items-center gap-xs font-medium text-foreground-default"> <RowIcon class="size-4" aria-hidden="true" /> {label} </span> <span class="flex min-w-0 flex-1 items-center gap-2xs overflow-hidden"> {@render header()} </span> {#if enabled} <ChevronRight class="size-4 shrink-0 text-foreground-muted transition-transform duration-200 ease-out-strong {rowOpen ? 'rotate-90' : ''}" aria-hidden="true" /> {/if} </button> <div id={`${id}-${key}`} inert={!rowOpen} class="grid transition-[grid-template-rows,opacity] duration-200 ease-out-strong motion-reduce:transition-opacity {rowOpen ? 'grid-rows-[1fr] opacity-100' : 'grid-rows-[0fr] opacity-0'}" > <div class="min-h-0 overflow-hidden"> <div class="border-t border-border-default px-sm py-xs"> {@render body()} </div> </div> </div> </div>{/snippet}
<div {id} bind:this={region} role="region" aria-label={month ? `Activity in ${title(month.monthsAgo)}` : undefined} inert={!open} class="grid transition-[grid-template-rows,opacity] duration-250 ease-out-strong motion-reduce:transition-opacity {open ? 'grid-rows-[1fr] opacity-100' : 'grid-rows-[0fr] opacity-0'}"> <div class="min-h-0 overflow-hidden"> {#if month} {@const current = month} <div {@attach slideIn(current.monthsAgo)} class="space-y-xs rounded-b-md border border-t-0 border-border-default bg-background-subtle p-sm" > {#snippet commitsHeader()} {@render repoTags( current.commitRepos.map((entry) => ({ repo: entry.repo, count: entry.commits })) )} {/snippet} {#snippet commitsBody()} <dl class="grid grid-cols-[minmax(0,10rem)_1fr] gap-x-sm gap-y-xs"> {#each current.commitRepos as entry (repoPath(entry.repo))} {@render repoTerm(entry.repo)} <dd class="flex min-w-0 flex-wrap gap-2xs"> {#each entry.recent as commit (commit.sha)} <a href={resolve( `${repoPath(entry.repo)}/commit/${commit.sha}` as "/" )} class="flex max-w-72 min-w-0 items-center gap-xs rounded-full px-xs py-3xs typography-paragraph-small text-foreground-default no-underline edge-ring-inset hover:bg-background-subtle hover:no-underline" > <span class="shrink-0 typography-monospace-small text-foreground-muted" >{commit.sha.slice(0, SHORT_SHA)}</span > <span class="min-w-0 truncate">{commit.subject}</span> </a> {/each} {#if entry.commits > entry.recent.length} <a href={resolve( `${repoPath(entry.repo)}/commits/HEAD` as "/" )} class="flex items-center rounded-full px-xs py-3xs typography-paragraph-small text-foreground-muted no-underline hover:bg-background-subtle hover:text-foreground-default hover:no-underline" > +{entry.commits - entry.recent.length} more </a> {/if} </dd> {/each} </dl> {/snippet} {@render row( "commits", GitCommit, pluralize(current.commits, "commit", "commits"), current.commitRepos.length > 0, commitsHeader, commitsBody )}
{#each tickets as ticketRow (ticketRow.key)} {#snippet ticketsHeader()} {@render repoTags( ticketRow.groups.map((group) => ({ repo: group.repo, count: group.items.length })) )} {/snippet} {#snippet ticketsBody()} <dl class="grid grid-cols-[minmax(0,10rem)_1fr] gap-x-sm gap-y-xs"> {#each ticketRow.groups as group (repoPath(group.repo))} {@render repoTerm(group.repo)} <dd class="flex min-w-0 flex-wrap gap-2xs"> {#each group.items as ticket (ticket.uri)} <ActivityTicket {ticket} kind={ticketRow.key} /> {/each} </dd> {/each} </dl> {/snippet} {@render row( ticketRow.key, ticketRow.icon, ticketRow.count, ticketRow.groups.length > 0, ticketsHeader, ticketsBody )} {/each}
{#snippet reposHeader()} {#each current.repos as repo (repoPath(repo))} <Tag icon={repo.forked ? GitFork : Plus} truncate class="min-w-0"> {repo.ownerHandle}/{repo.name} </Tag> {/each} {/snippet} {#snippet reposBody()} <ul class="flex flex-col gap-xs"> {#each current.repos as repo (repoPath(repo))} <li class="flex min-w-0 flex-col gap-3xs typography-paragraph-small"> <span class="flex min-w-0 items-center gap-xs"> <a href={repoHref(repo)} class="flex min-w-0 items-center gap-2xs font-medium text-foreground-default hover:underline" > {@render repoLabel(repo)} </a> <Tag color="muted" icon={repo.forked ? GitFork : Plus}> {repo.forked ? "Forked" : "Created"} </Tag> </span> {#if repo.description} <p class="text-foreground-muted">{repo.description}</p> {/if} </li> {/each} </ul> {/snippet} {@render row( "repos", BookPlus, pluralize(current.repos.length, "new repository", "new repositories"), current.repos.length > 0, reposHeader, reposBody )} </div> {/if} </div></div>