Radish alpha
r
rad:z4D5UCArafTzTQpDZNQRuqswh3ury
Radicle desktop app
Radicle
Git
Simplify comment/revision action binding
Merged did:key:z6Mki9XN...FvWF opened 9 months ago

Simplify and streamline how comment actions (e.g. editComment) and revision actions (e.g. editRevision) are passed down to to components and bound to comment and revision instances

6 files changed +19 -44 a8486548 a33799d6
modified src/components/Diff.svelte
@@ -17,7 +17,6 @@
      embeds: Embed[],
    ) => Promise<void>;
    reactOnComment?: (
-
      publicKey: string,
      commentId: string,
      authors: Author[],
      reaction: string,
@@ -436,8 +435,7 @@
        inline
        rid={codeComments.rid}
        {thread}
-
        reactOnComment={codeComments.reactOnComment &&
-
          partial(codeComments.reactOnComment, codeComments.config.publicKey)}
+
        reactOnComment={codeComments.reactOnComment}
        createReply={(codeComments.canReply ?? true)
          ? async (body, embeds) => {
              await codeComments.createComment(body, embeds, thread.root.id);
modified src/components/Discussion.svelte
@@ -31,7 +31,6 @@
      embeds: Embed[],
    ) => Promise<void>;
    reactOnComment: (
-
      publicKey: string,
      commentId: string,
      authors: Author[],
      reaction: string,
@@ -149,7 +148,7 @@
        )}
        {editComment}
        createReply={createComment}
-
        reactOnComment={partial(reactOnComment, config.publicKey)} />
+
        {reactOnComment} />
      <div class="connector"></div>
    {/each}

modified src/components/Review.svelte
@@ -221,7 +221,6 @@
  }

  async function reactOnComment(
-
    publicKey: string,
    commentId: string,
    authors: Author[],
    reaction: string,
@@ -239,7 +238,7 @@
          reaction,
          review: review.id,
          active: !authors.find(
-
            ({ did }) => publicKeyFromDid(did) === publicKey,
+
            ({ did }) => publicKeyFromDid(did) === config.publicKey,
          ),
        },
        opts: { announce: $nodeRunning && $announce },
modified src/components/Revision.svelte
@@ -5,8 +5,6 @@
  import type { Thread } from "@bindings/cob/thread/Thread";
  import type { Config } from "@bindings/config/Config";

-
  import partial from "lodash/partial";
-

  import { nodeRunning } from "@app/lib/events";
  import { invoke } from "@app/lib/invoke";
  import * as roles from "@app/lib/roles";
@@ -49,18 +47,14 @@
        }, [])) as Thread[]) || [],
  );

-
  async function editRevision(
-
    revisionId: string,
-
    description: string,
-
    embeds: Embed[],
-
  ) {
+
  async function editRevision(description: string, embeds: Embed[]) {
    try {
      await invoke("edit_patch", {
        rid: rid,
        cobId: patchId,
        action: {
          type: "revision.edit",
-
          revision: revisionId,
+
          revision: revision.id,
          description,
          embeds,
        },
@@ -73,22 +67,17 @@
    }
  }

-
  async function reactOnRevision(
-
    publicKey: string,
-
    revisionId: string,
-
    authors: Author[],
-
    reaction: string,
-
  ) {
+
  async function reactOnRevision(authors: Author[], reaction: string) {
    try {
      await invoke("edit_patch", {
        rid: rid,
        cobId: patchId,
        action: {
          type: "revision.react",
-
          revision: revisionId,
+
          revision: revision.id,
          reaction,
          active: !authors.find(
-
            ({ did }) => publicKeyFromDid(did) === publicKey,
+
            ({ did }) => publicKeyFromDid(did) === config.publicKey,
          ),
        },
        opts: { announce: $nodeRunning && $announce },
@@ -140,7 +129,6 @@
  }

  async function reactOnComment(
-
    publicKey: string,
    commentId: string,
    authors: Author[],
    reaction: string,
@@ -155,7 +143,7 @@
          reaction,
          revision: revision.id,
          active: !authors.find(
-
            ({ did }) => publicKeyFromDid(did) === publicKey,
+
            ({ did }) => publicKeyFromDid(did) === config.publicKey,
          ),
        },
        opts: { announce: $nodeRunning && $announce },
@@ -200,12 +188,12 @@
    reactions={revision.reactions}
    timestamp={revision.timestamp}
    body={revision.description.slice(-1)[0].body}
-
    reactOnComment={partial(reactOnRevision, config.publicKey, revision.id)}
+
    reactOnComment={reactOnRevision}
    editComment={roles.isDelegateOrAuthor(
      config.publicKey,
      repoDelegates.map(delegate => delegate.did),
      revision.author.did,
-
    ) && partial(editRevision, revision.id)}>
+
    ) && editRevision}>
  </CommentComponent>
</div>

modified src/components/Thread.svelte
@@ -4,7 +4,6 @@
  import type { Embed } from "@bindings/cob/thread/Embed";
  import type { Thread } from "@bindings/cob/thread/Thread";

-
  import partial from "lodash/partial";
  import { tick } from "svelte";

  import { scrollIntoView } from "@app/lib/utils";
@@ -111,11 +110,9 @@
          reactions={reply.reactions}
          timestamp={reply.edits[0].timestamp}
          body={reply.edits.slice(-1)[0].body}
-
          editComment={editComment &&
-
            canEditComment(reply.author.did) &&
-
            partial(editComment, reply.id)}
-
          reactOnComment={reactOnComment &&
-
            partial(reactOnComment, reply.id)} />
+
          editComment={canEditComment(root.author.did) &&
+
            editComment?.bind(null, root.id)}
+
          reactOnComment={reactOnComment?.bind(null, root.id)} />
      {/each}
    {/if}
    {#if createReply && showReplyForm}
@@ -153,10 +150,9 @@
      reactions={root.reactions}
      timestamp={root.edits.slice(-1)[0].timestamp}
      body={root.edits.slice(-1)[0].body}
-
      editComment={editComment &&
-
        canEditComment(root.author.did) &&
-
        partial(editComment, root.id)}
-
      reactOnComment={reactOnComment && partial(reactOnComment, root.id)}>
+
      editComment={canEditComment(root.author.did) &&
+
        editComment?.bind(null, root.id)}
+
      reactOnComment={reactOnComment?.bind(null, root.id)}>
      {#snippet actions()}
        {#if createReply}
          <Icon name="reply" onclick={toggleReply} />
modified src/views/repo/Issue.svelte
@@ -226,7 +226,6 @@
  }

  async function reactOnComment(
-
    publicKey: string,
    commentId: string,
    authors: Author[],
    reaction: string,
@@ -240,7 +239,7 @@
          id: commentId,
          reaction,
          active: !authors.find(
-
            ({ did }) => publicKeyFromDid(did) === publicKey,
+
            ({ did }) => publicKeyFromDid(did) === config.publicKey,
          ),
        },
        opts: { announce: $nodeRunning && $announce },
@@ -459,11 +458,7 @@
          repo.delegates.map(delegate => delegate.did),
          issue.body.author.did,
        ) && partial(editComment, issue.body.id)}
-
        reactOnComment={partial(
-
          reactOnComment,
-
          config.publicKey,
-
          issue.body.id,
-
        )}>
+
        reactOnComment={partial(reactOnComment, issue.body.id)}>
      </CommentComponent>
    </div>