diff --git a/httpd-client/lib/project/patch.ts b/httpd-client/lib/project/patch.ts index 24e39553c..3f5141085 100644 --- a/httpd-client/lib/project/patch.ts +++ b/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; -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; 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; +}); 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"; diff --git a/src/views/projects/Cob/Revision.svelte b/src/views/projects/Cob/Revision.svelte index 903d1aa4b..6b70f6391 100644 --- a/src/views/projects/Cob/Revision.svelte +++ b/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) | undefined; + export let editRevision: + | ((description: string, embeds: Embed[]) => Promise) + | undefined; export let editComment: | ((commentId: string, body: string, embeds: Embed[]) => Promise) | undefined; @@ -245,11 +247,7 @@
- { - expanded = !expanded; - }} /> + (expanded = !expanded)} /> Revision {utils.formatObjectId(revisionId)} @@ -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"; } diff --git a/src/views/projects/Patch.svelte b/src/views/projects/Patch.svelte index 0774258bd..479204ab9 100644 --- a/src/views/projects/Patch.svelte +++ b/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 @@
{#if session && patchState !== "read"} + {@const latestEdit = patch.revisions[0].edits.pop()} (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"; }