Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add embeds to patches
Sebastian Martinez committed 2 years ago
commit c1740beb1260a67e21d506fb993ae61d70b2fdad
parent 5e5f7fc12fe5f3accb6bad16208d362daecec3e7
4 files changed +36 -20
modified src/components/Comment.svelte
@@ -1,4 +1,6 @@
<script lang="ts" strictEvents>
+
  import type { Embed } from "@app/lib/file";
+

  import { createEventDispatcher, tick } from "svelte";

  import { authenticated } from "@app/lib/httpd";
@@ -16,6 +18,7 @@
  export let authorId: string;
  export let authorAlias: string | undefined = undefined;
  export let body: string;
+
  export let enableAttachments: boolean = false;
  export let reactions: [string, string][];
  export let caption = "commented";
  export let rawPath: string;
@@ -29,7 +32,7 @@

  const dispatch = createEventDispatcher<{
    react: { nids: string[]; id: string; reaction: string };
-
    edit: string;
+
    edit: { comment: string; embeds: Embed[] };
  }>();

  $: groupedReactions = reactions?.reduce(
@@ -144,12 +147,12 @@
    {#if editInProgress}
      <ExtendedTextarea
        {body}
-
        enableAttachments
+
        {enableAttachments}
        submitCaption="Save"
        placeholder="Leave your description"
-
        on:submit={({ detail: { comment } }) => {
+
        on:submit={({ detail: { comment, embeds } }) => {
          editInProgress = false;
-
          dispatch("edit", comment);
+
          dispatch("edit", { comment, embeds });
        }}
        on:close={async () => {
          body = body;
modified src/components/Thread.svelte
@@ -1,5 +1,6 @@
<script lang="ts" strictEvents>
  import type { Comment } from "@httpd-client";
+
  import type { Embed } from "@app/lib/file";

  import { createEventDispatcher, tick } from "svelte";
  import { httpdStore } from "@app/lib/httpd";
@@ -25,10 +26,10 @@
  const dispatch = createEventDispatcher<{
    reply: {
      id: string;
-
      embeds: { name: string; content: string }[];
+
      embeds: Embed[];
      body: string;
    };
-
    editComment: { id: string; body: string };
+
    editComment: { id: string; body: string; embeds: Embed[] };
    react: { nids: string[]; commentId: string | undefined; reaction: string };
    cancel: never;
  }>();
@@ -73,8 +74,12 @@
      timestamp={root.timestamp}
      disableEdit={root.embeds.length > 0}
      body={root.body}
-
      on:edit={event =>
-
        dispatch("editComment", { id: root.id, body: event.detail })}
+
      on:edit={({ detail }) =>
+
        dispatch("editComment", {
+
          id: root.id,
+
          body: detail.comment,
+
          embeds: detail.embeds,
+
        })}
      on:react>
      <IconSmall name="chat" slot="icon" />
    </CommentComponent>
@@ -94,8 +99,12 @@
          timestamp={reply.timestamp}
          disableEdit={reply.embeds.length > 0}
          body={reply.body}
-
          on:edit={event =>
-
            dispatch("editComment", { id: reply.id, body: event.detail })}
+
          on:edit={({ detail }) =>
+
            dispatch("editComment", {
+
              id: reply.id,
+
              body: detail.comment,
+
              embeds: detail.embeds,
+
            })}
          on:react />
      {/each}
    </div>
modified src/views/projects/Cob/Revision.svelte
@@ -385,6 +385,7 @@
        {#if element.type === "thread"}
          <div class="connector" />
          <Thread
+
            enableAttachments
            rawPath={utils.getRawBasePath(projectId, baseUrl, projectHead)}
            thread={element.inner}
            on:editComment
modified src/views/projects/Patch.svelte
@@ -182,7 +182,7 @@

  async function createReply({
    detail: reply,
-
  }: CustomEvent<{ id: string; body: string }>) {
+
  }: CustomEvent<{ id: string; body: string; embeds: Embed[] }>) {
    if ($authenticated && reply.body.trim().length > 0) {
      const status = await updatePatch(
        project.id,
@@ -191,6 +191,7 @@
          type: "revision.comment",
          revision: revisionId,
          body: reply.body,
+
          embeds: reply.embeds,
          replyTo: reply.id,
        },
        $authenticated.session,
@@ -232,14 +233,17 @@
      }
    }
  }
-
  async function createComment(commentBody: string) {
-
    if ($authenticated && commentBody.trim().length > 0) {
+
  async function createComment({
+
    detail: { comment, embeds },
+
  }: CustomEvent<{ comment: string; embeds: Embed[] }>) {
+
    if ($authenticated && comment.trim().length > 0) {
      const status = await updatePatch(
        project.id,
        patch.id,
        {
          type: "revision.comment",
-
          body: commentBody,
+
          body: comment,
+
          embeds,
          revision: revisionId,
        },
        $authenticated.session,
@@ -252,8 +256,8 @@
  }

  async function editComment({
-
    detail: { id, body },
-
  }: CustomEvent<{ id: string; body: string }>) {
+
    detail: { id, body, embeds },
+
  }: CustomEvent<{ id: string; body: string; embeds: Embed[] }>) {
    if ($authenticated && body.trim().length > 0) {
      const status = await updatePatch(
        project.id,
@@ -263,7 +267,7 @@
          comment: id,
          body,
          revision: revisionId,
-
          embeds: [],
+
          embeds,
        },
        $authenticated.session,
        api,
@@ -779,10 +783,9 @@
              {#if $httpdStore.state === "authenticated" && view.name === "activity"}
                <div class="connector" />
                <CommentToggleInput
+
                  enableAttachments
                  placeholder="Leave your comment"
-
                  on:submit={async event => {
-
                    await createComment(event.detail.comment);
-
                  }} />
+
                  on:submit={createComment} />
                <div class="connector" />
                <div style="display: flex;">
                  <CobStateButton