Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
Svelte
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134<script lang="ts"> import type { Did } from "@atcute/lexicons/syntax"; import { resolve } from "$app/paths"; import { untrack } from "svelte"; import { loadDiff, type RepoDiff, type RepoDiffDeps, type RepoDiffSpec } from "$lib/api/repoDiff"; import { browser } from "$app/environment"; import { formatPatchUrl } from "$lib/api/knotmirror"; import { getPatchStream } from "$lib/api/patchStream"; import type { CommitDetail } from "$lib/api/repo"; import { FULL_HASH_RE } from "$lib/api/repo"; import CommitHeader from "$lib/components/repo/CommitHeader.svelte"; import DiffView from "$lib/components/repo/DiffView.svelte"; import type { CodeViewFile } from "$lib/components/repo/DiffCodeView.svelte"; import { blobHref } from "$lib/components/repo/urls"; import type { DiffStyle } from "$lib/components/repo/pierre"; import TabPanel from "$lib/components/ui/TabPanel.svelte"; import type { CommitStatuses } from "$lib/api/commitStatuses";
interface Props { ownerHandle: string; repoName: string; // bobbin's repo did, which is how the mirror names this repo repoDid?: Did; // the ref the page was loaded with. raw downloads only work for full hashes ref: string; commit: CommitDetail; // hex of the first parent, empty for a root commit parent?: string; changeId?: string; // the commit diff always comes from the mirror. pendingSpec: the payload was // too big to buffer through ssr, so the browser fetches it on mount mirror: { diff?: RepoDiff; error?: string; pendingSpec?: RepoDiffSpec; deps: RepoDiffDeps; }; // side-by-side or stacked diffStyle?: DiffStyle; pipelineStatuses?: Promise<CommitStatuses>; }
let { ownerHandle, repoName, repoDid, ref, commit, parent = "", changeId = "", mirror, diffStyle = "unified", pipelineStatuses }: Props = $props();
const base = $derived(`/${ownerHandle}/${repoName}`);
const blobUrl = $derived((file: CodeViewFile) => file.kind === "deleted" ? undefined : blobHref(ownerHandle, repoName, commit.hash, file.name) );
let deferred = $state<{ spec?: RepoDiffSpec; diff?: RepoDiff; error?: string }>({}); $effect(() => { const spec = mirror.pendingSpec; if (!spec || deferred.spec === spec) return; deferred = { spec }; const deps = untrack(() => mirror.deps); loadDiff(deps, spec).then( (diff) => { if (deferred.spec === spec) deferred = { spec, diff }; }, () => { if (deferred.spec === spec) { deferred = { spec, error: "Could not load commit diff from the mirror" }; } } ); }); const mirrorDiff = $derived( mirror.pendingSpec && deferred.spec === mirror.pendingSpec ? deferred.diff : mirror.diff ); const mirrorError = $derived( mirror.pendingSpec && deferred.spec === mirror.pendingSpec ? deferred.error : mirror.error ); const mirrorLoading = $derived(Boolean(mirror.pendingSpec) && !mirrorDiff && !mirrorError);
// the raw commit route only accepts full sha1/sha256 hex, anything shorter 404s const downloadUrls = $derived( FULL_HASH_RE.test(ref) ? { patch: resolve(`${base}/commit/${ref}.patch` as "/"), diff: resolve(`${base}/commit/${ref}.diff` as "/") } : undefined ); const patchUrl = $derived( repoDid && parent && mirror.deps.git.via === "mirror" ? formatPatchUrl(mirror.deps.git.ctx.serviceUrl, { repo: repoDid, from: parent, to: ref }) : undefined );
// Lookup rather than effect to avoid transient undefined triggering duplicate fetch. const patch = $derived(browser && patchUrl ? getPatchStream(patchUrl) : undefined);</script>
<div class="flex flex-col gap-4 pb-4"> <TabPanel class="rounded-tl-none"> <CommitHeader {ownerHandle} {repoName} {commit} {parent} {changeId} {pipelineStatuses} /> </TabPanel> <DiffView deps={mirror.deps} diff={mirrorDiff} error={mirrorError} loading={mirrorLoading} {blobUrl} {diffStyle} styleHref={(style) => `?diff=${style}`} {downloadUrls} {patchUrl} {patch} /></div>