Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add embeds to patch descriptions
Sebastian Martinez committed 2 years ago
commit aed853821828e9a02f052258f79050931a2f92e6
parent 28598e65cd47c02e238eba4f0c949f151353d6ec
3 files changed +36 -25
modified httpd-client/lib/project/patch.ts
@@ -1,4 +1,4 @@
-
import type { Comment, Embed } from "./comment.js";
+
import type { Embed } from "./comment.js";
import type { ZodSchema, z } from "zod";

import { commentSchema } from "./comment.js";
@@ -71,29 +71,27 @@ const reviewSchema = object({
  timestamp: number(),
}) satisfies ZodSchema<Review>;

-
export interface Revision {
-
  id: string;
-
  author: { id: string; alias?: string };
-
  description: string;
-
  base: string;
-
  oid: string;
-
  refs: string[];
-
  discussions: Comment[];
-
  reviews: Review[];
-
  timestamp: number;
-
}
+
export type Revision = z.infer<typeof revisionSchema>;

const revisionSchema = object({
  id: string(),
  author: object({ id: string(), alias: string().optional() }),
  description: string(),
+
  edits: array(
+
    object({
+
      author: object({ id: string(), alias: string().optional() }),
+
      body: string(),
+
      embeds: array(object({ name: string(), content: string() })),
+
      timestamp: number(),
+
    }),
+
  ),
  base: string(),
  oid: string(),
  refs: array(string()),
  discussions: array(commentSchema),
  reviews: array(reviewSchema),
  timestamp: number(),
-
}) satisfies ZodSchema<Revision>;
+
});

export interface Patch {
  id: string;
@@ -185,7 +183,12 @@ export type PatchUpdateAction =
      active: boolean;
    }
  | { type: "revision"; description: string; base: string; oid: string }
-
  | { type: "revision.edit"; revision: string; description: string }
+
  | {
+
      type: "revision.edit";
+
      revision: string;
+
      description: string;
+
      embeds?: Embed[];
+
    }
  | { type: "revision.redact"; revision: string }
  | {
      type: "revision.comment";
modified src/views/projects/Cob/Revision.svelte
@@ -48,7 +48,9 @@
  export let previousRevOid: string | undefined = undefined;
  export let first: boolean;
  export let canEdit: (author: string) => true | undefined;
-
  export let editRevision: ((description: string) => Promise<void>) | undefined;
+
  export let editRevision:
+
    | ((description: string, embeds: Embed[]) => Promise<void>)
+
    | undefined;
  export let editComment:
    | ((commentId: string, body: string, embeds: Embed[]) => Promise<void>)
    | undefined;
@@ -245,11 +247,7 @@
  <div class="revision-box" class:expanded>
    <div class="revision-header">
      <div class="revision-name">
-
        <ExpandButton
-
          {expanded}
-
          on:toggle={() => {
-
            expanded = !expanded;
-
          }} />
+
        <ExpandButton {expanded} on:toggle={() => (expanded = !expanded)} />
        <span>
          Revision
          <span class="global-hash">{utils.formatObjectId(revisionId)}</span>
@@ -410,10 +408,10 @@
              submitInProgress={revisionState === "submit"}
              placeholder="Leave a description"
              on:close={() => (revisionState = "read")}
-
              on:submit={async ({ detail: { comment } }) => {
+
              on:submit={async ({ detail: { comment, embeds } }) => {
                revisionState = "submit";
                try {
-
                  await editRevision_(comment);
+
                  await editRevision_(comment, Array.from(embeds.values()));
                } finally {
                  revisionState = "read";
                }
modified src/views/projects/Patch.svelte
@@ -50,6 +50,7 @@
  import uniqBy from "lodash/uniqBy";
  import { HttpdClient } from "@httpd-client";
  import { httpdStore, type Session } from "@app/lib/httpd";
+
  import { parseEmbedIntoMap } from "@app/lib/file";

  import Badge from "@app/components/Badge.svelte";
  import Button from "@app/components/Button.svelte";
@@ -125,12 +126,13 @@
    sessionId: string,
    revisionId: string,
    description: string,
+
    embeds: Embed[],
  ) {
    try {
      await api.project.updatePatch(
        project.id,
        patch.id,
-
        { type: "revision.edit", revision: revisionId, description },
+
        { type: "revision.edit", revision: revisionId, description, embeds },
        sessionId,
      );
    } catch (error) {
@@ -693,20 +695,28 @@
        <svelte:fragment slot="description">
          <div class="revision-description">
            {#if session && patchState !== "read"}
+
              {@const latestEdit = patch.revisions[0].edits.pop()}
              <ExtendedTextarea
                validateBody={false}
+
                enableAttachments
+
                embeds={latestEdit && parseEmbedIntoMap(latestEdit.embeds)}
                rawPath={rawPath(patch.revisions[0].id)}
                body={newDescription}
                submitCaption="Save"
                submitInProgress={patchState === "submit"}
                placeholder="Leave a description"
                on:close={() => (patchState = "read")}
-
                on:submit={async ({ detail: { comment } }) => {
+
                on:submit={async ({ detail: { comment, embeds } }) => {
                  patchState = "submit";
                  if (session) {
                    try {
                      await editPatch(session.id, patch.title);
-
                      await editRevision(session.id, patch.id, comment);
+
                      await editRevision(
+
                        session.id,
+
                        patch.id,
+
                        comment,
+
                        Array.from(embeds.values()),
+
                      );
                    } finally {
                      patchState = "read";
                    }