Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
revision activity: add expandable commit diffs
✓ CI success Brandon Oxendine committed 1 month ago
commit b1a8f80c961878a807b589b7f46a8dd6ef814bb9
parent f20d6d320acf87311d4d4066feed89927130f639
1 passed (1 total) View logs
4 files changed +72 -8
modified src/components/CommitActivityItem.svelte
@@ -1,16 +1,35 @@
<script lang="ts">
+
  import type { FileDiff as FileDiffType } from "@bindings/diff/FileDiff";
  import type { Commit } from "@bindings/repo/Commit";

+
  import { cachedGetDiff } from "@app/lib/invoke";
  import { absoluteTimestamp, formatTimestamp } from "@app/lib/utils";

+
  import FileDiff from "@app/components/FileDiff.svelte";
  import Icon from "@app/components/Icon.svelte";
  import Id from "@app/components/Id.svelte";

  interface Props {
    commit: Commit;
+
    rid: string;
  }

-
  const { commit }: Props = $props();
+
  const { commit, rid }: Props = $props();
+

+
  let expanded = $state(false);
+

+
  const parent = $derived(commit.parents[0]);
+

+
  function toggle() {
+
    expanded = !expanded;
+
  }
+

+
  function fileKey(file: FileDiffType): string {
+
    if (file.status === "moved" || file.status === "copied") {
+
      return `${file.oldPath}->${file.newPath}`;
+
    }
+
    return file.path;
+
  }
</script>

<style>
@@ -19,6 +38,7 @@
    align-items: flex-start;
    gap: 0.5rem;
    min-width: 0;
+
    cursor: pointer;
  }
  .wrapper {
    display: flex;
@@ -44,11 +64,31 @@
  .timestamp {
    color: var(--color-text-quaternary);
  }
+
  .diff {
+
    margin: 0.5rem 0 0 2rem;
+
    display: flex;
+
    flex-direction: column;
+
    gap: 0.5rem;
+
  }
+
  .fallback {
+
    margin: 0.5rem 0 0 2rem;
+
    color: var(--color-text-secondary);
+
  }
</style>

-
<div class="timeline-item txt-body-m-regular">
+
<div
+
  class="timeline-item txt-body-m-regular"
+
  role="button"
+
  tabindex="0"
+
  onclick={toggle}
+
  onkeydown={e => {
+
    if (e.key === "Enter" || e.key === " ") {
+
      e.preventDefault();
+
      toggle();
+
    }
+
  }}>
  <div class="icon">
-
    <Icon name="commit" />
+
    <Icon name={expanded ? "chevron-down" : "commit"} />
  </div>
  <div class="wrapper">
    <span class="author">{commit.author.name}</span>
@@ -62,3 +102,25 @@
    </div>
  </div>
</div>
+

+
{#if expanded}
+
  {#if !parent}
+
    <div class="fallback txt-body-m-regular">
+
      Initial commit; no diff to show.
+
    </div>
+
  {:else}
+
    {#await cachedGetDiff( rid, { base: parent, head: commit.id, unified: 3, highlight: true }, )}
+
      <div class="fallback txt-body-m-regular">Loading diff…</div>
+
    {:then diff}
+
      <div class="diff">
+
        {#each diff.files as file (fileKey(file))}
+
          <FileDiff {file} head={commit.id} expanded />
+
        {/each}
+
      </div>
+
    {:catch error}
+
      <div class="fallback txt-body-m-regular">
+
        Failed to load diff: {error.message ?? error}
+
      </div>
+
    {/await}
+
  {/if}
+
{/if}
modified src/components/CommitGroupActivityItem.svelte
@@ -6,10 +6,11 @@

  interface Props {
    commits: Commit[];
+
    rid: string;
    expandBatch?: number;
  }

-
  const { commits, expandBatch = 10 }: Props = $props();
+
  const { commits, rid, expandBatch = 10 }: Props = $props();

  let expanded = $state(0);

@@ -61,7 +62,7 @@
</style>

{#each visible as commit, idx (commit.id)}
-
  <CommitActivityItem {commit} />
+
  <CommitActivityItem {commit} {rid} />
  {#if idx < visible.length - 1 || remaining > 0}
    <div class="connector"></div>
  {/if}
modified src/components/PatchActivityItem.svelte
@@ -249,7 +249,8 @@
      <div class="wrapper">
        <NodeId {...authorForNodeId(op.author)} />
        <div class="summary-line">
-
          changed title <s>{op.previous.title}</s> → {op.title}
+
          changed title <s>{op.previous.title}</s>
+
          → {op.title}
        </div>
        <div class="timestamp" title={absoluteTimestamp(op.timestamp)}>
          {formatTimestamp(op.timestamp)}
modified src/components/Revision.svelte
@@ -391,9 +391,9 @@
    {#if data.kind === "op"}
      <PatchActivityItem op={data.op} {patchId} />
    {:else if data.kind === "commit"}
-
      <CommitActivityItem commit={data.commit} />
+
      <CommitActivityItem commit={data.commit} {rid} />
    {:else if data.kind === "commitGroup"}
-
      <CommitGroupActivityItem commits={data.commits} />
+
      <CommitGroupActivityItem commits={data.commits} {rid} />
    {:else}
      <ReviewCodeThread
        {rid}