diff --git a/src/components/Revision.svelte b/src/components/Revision.svelte new file mode 100644 index 000000000..fd743cd14 --- /dev/null +++ b/src/components/Revision.svelte @@ -0,0 +1,368 @@ + + + + +
+ 1 + ? revision.description.at(-1) + : undefined} + author={revision.author} + reactions={revision.reactions} + timestamp={revision.timestamp} + body={revision.description.slice(-1)[0].body} + reactOnComment={partial(reactOnRevision, config.publicKey, revision.id)} + editComment={roles.isDelegateOrAuthor( + config.publicKey, + repoDelegates.map(delegate => delegate.did), + revision.author.did, + ) && partial(editRevision, revision.id)}> + {#snippet actions()} + + {/snippet} + +
+ +
+ +
(hideDiscussion = !hideDiscussion)}> + Discussion +
+
+ {#each threads as thread} + delegate.did), + )} + editComment={partial(editComment)} + createReply={partial(createReply)} + reactOnComment={partial(reactOnComment, config.publicKey)} /> +
+ {/each} + +
+ (topLevelReplyOpen = false) + : undefined} + placeholder="Leave a comment" + submit={partial(createComment)} /> +
+
+
+ +
+ +
(hideChanges = !hideChanges)}> + Changes +
+
+ {#await loadHighlightedDiff(rid, revision.base, revision.head)} + Loading… + {:then diff} + + {/await} +
+
+ +
+ +
(hideTimeline = !hideTimeline)}> + Timeline +
+
+ +
+
diff --git a/src/views/repo/Patch.svelte b/src/views/repo/Patch.svelte index 194bdcc71..9ec5b2faf 100644 --- a/src/views/repo/Patch.svelte +++ b/src/views/repo/Patch.svelte @@ -2,37 +2,25 @@ import type { Action } from "@bindings/cob/patch/Action"; import type { Author } from "@bindings/cob/Author"; import type { Config } from "@bindings/config/Config"; - import type { Diff } from "@bindings/diff/Diff"; - import type { Embed } from "@bindings/cob/thread/Embed"; import type { Operation } from "@bindings/cob/Operation"; import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery"; import type { Patch } from "@bindings/cob/patch/Patch"; import type { PatchStatus } from "./router"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; import type { Revision } from "@bindings/cob/patch/Revision"; - import type { Thread } from "@bindings/cob/thread/Thread"; - - import partial from "lodash/partial"; - import { tick } from "svelte"; import * as roles from "@app/lib/roles"; + import { announce } from "@app/components/AnnounceSwitch.svelte"; import { formatOid, patchStatusBackgroundColor, patchStatusColor, - publicKeyFromDid, - scrollIntoView, } from "@app/lib/utils"; import { invoke } from "@app/lib/invoke"; import { nodeRunning } from "@app/lib/events"; - import { announce } from "@app/components/AnnounceSwitch.svelte"; - import AssigneeInput from "@app/components/AssigneeInput.svelte"; import Border from "@app/components/Border.svelte"; - import Changeset from "@app/components/Changeset.svelte"; - import CommentComponent from "@app/components/Comment.svelte"; - import CommentToggleInput from "@app/components/CommentToggleInput.svelte"; import CopyableId from "@app/components/CopyableId.svelte"; import Icon from "@app/components/Icon.svelte"; import InlineTitle from "@app/components/InlineTitle.svelte"; @@ -41,11 +29,10 @@ import PatchStateBadge from "@app/components/PatchStateBadge.svelte"; import PatchStateButton from "@app/components/PatchStateButton.svelte"; import PatchTeaser from "@app/components/PatchTeaser.svelte"; - import PatchTimeline from "@app/components/PatchTimeline.svelte"; + import RevisionComponent from "@app/components/Revision.svelte"; import Sidebar from "@app/components/Sidebar.svelte"; import Tab from "@app/components/Tab.svelte"; import TextInput from "@app/components/TextInput.svelte"; - import ThreadComponent from "@app/components/Thread.svelte"; interface Props { repo: RepoInfo; @@ -78,32 +65,6 @@ let labelSaveInProgress: boolean = $state(false); let assigneesSaveInProgress: boolean = $state(false); let tab: "patch" | "revisions" = $state("patch"); - let hideDiscussion = $state(false); - let hideChanges = $state(false); - let hideTimeline = $state(false); - let focusReply: boolean = $state(false); - let topLevelReplyOpen = $state(false); - let latestRevision = $derived(revisions.slice(-1)[0]); - - const threads = $derived( - ((revisions[0].discussion && - revisions[0].discussion - .filter( - comment => - (comment.id !== revisions[0].id && !comment.replyTo) || - comment.replyTo === revisions[0].id, - ) - .map(thread => { - return { - root: thread, - replies: - revisions[0].discussion && - revisions[0].discussion - .filter(comment => comment.replyTo === thread.id) - .sort((a, b) => a.edits[0].timestamp - b.edits[0].timestamp), - }; - }, [])) as Thread[]) || [], - ); $effect(() => { items = patches.content; @@ -118,13 +79,25 @@ tab = "patch"; editingTitle = false; updatedTitle = patch.title; - hideDiscussion = false; - hideChanges = false; - hideTimeline = false; }); const project = $derived(repo.payloads["xyz.radicle.project"]!); + async function loadPatch(rid: string, patchId: string) { + patch = await invoke("patch_by_id", { + rid: rid, + id: patchId, + }); + revisions = await invoke("revisions_by_patch", { + rid: rid, + id: patchId, + }); + activity = await invoke[]>("activity_by_patch", { + rid: repo.rid, + id: patch.id, + }); + } + async function editTitle(rid: string, patchId: string, title: string) { if (patch.title === updatedTitle) { editingTitle = false; @@ -212,175 +185,6 @@ } } - async function editRevision( - revisionId: string, - description: string, - embeds: Embed[], - ) { - try { - await invoke("edit_patch", { - rid: repo.rid, - cobId: patch.id, - action: { - type: "revision.edit", - revision: revisionId, - description, - embeds, - }, - opts: { announce: $nodeRunning && $announce }, - }); - } catch (error) { - console.error("Editing revision failed: ", error); - } finally { - await reload(); - } - } - - async function reactOnRevision( - publicKey: string, - revisionId: string, - authors: Author[], - reaction: string, - ) { - try { - await invoke("edit_patch", { - rid: repo.rid, - cobId: patch.id, - action: { - type: "revision.react", - revision: revisionId, - reaction, - active: !authors.find( - ({ did }) => publicKeyFromDid(did) === publicKey, - ), - }, - opts: { announce: $nodeRunning && $announce }, - }); - } catch (error) { - console.error("Editing reactions failed", error); - } finally { - await reload(); - } - } - - async function editComment(commentId: string, body: string, embeds: Embed[]) { - try { - await invoke("edit_patch", { - rid: repo.rid, - cobId: patch.id, - action: { - type: "revision.comment.edit", - comment: commentId, - body, - revision: revisions[0].id, - embeds, - }, - opts: { announce: $nodeRunning && $announce }, - }); - } catch (error) { - console.error("Eediting comment failed: ", error); - } finally { - await reload(); - } - } - - async function createReply(replyTo: string, body: string, embeds: Embed[]) { - try { - await invoke("create_patch_comment", { - rid: repo.rid, - new: { id: patch.id, body, embeds, replyTo, revision: revisions[0].id }, - opts: { announce: $nodeRunning && $announce }, - }); - } catch (error) { - console.error("Creating reply failed", error); - } finally { - await reload(); - } - } - - async function reactOnComment( - publicKey: string, - commentId: string, - authors: Author[], - reaction: string, - ) { - try { - await invoke("edit_patch", { - rid: repo.rid, - cobId: patch.id, - action: { - type: "revision.comment.react", - comment: commentId, - reaction, - revision: revisions[0].id, - active: !authors.find( - ({ did }) => publicKeyFromDid(did) === publicKey, - ), - }, - opts: { announce: $nodeRunning && $announce }, - }); - } catch (error) { - console.error("Editing comment reactions failed", error); - } finally { - await reload(); - } - } - - async function createComment(body: string, embeds: Embed[]) { - try { - await invoke("create_patch_comment", { - rid: repo.rid, - new: { id: patch.id, body, embeds, revision: revisions[0].id }, - opts: { announce: $nodeRunning && $announce }, - }); - } catch (error) { - console.error("Creating comment failed: ", error); - } finally { - await reload(); - } - } - - async function toggleReply() { - topLevelReplyOpen = !topLevelReplyOpen; - if (!topLevelReplyOpen) { - return; - } - - await tick(); - scrollIntoView(`reply-${patch.id}`, { - behavior: "smooth", - block: "center", - }); - focusReply = true; - } - - async function loadPatch(rid: string, patchId: string) { - patch = await invoke("patch_by_id", { - rid: rid, - id: patchId, - }); - revisions = await invoke("revisions_by_patch", { - rid: rid, - id: patchId, - }); - activity = await invoke[]>("activity_by_patch", { - rid: repo.rid, - id: patch.id, - }); - } - - async function loadHighlightedDiff(rid: string, base: string, head: string) { - return invoke("get_diff", { - rid, - options: { - base, - head, - unified: 5, - highlight: true, - }, - }); - } - async function loadMoreSecondColumn() { if (more) { const p = await invoke>("list_patches", { @@ -456,23 +260,6 @@ padding: 1rem 1rem 1rem 0; } - .patch-body { - margin-bottom: 1rem; - position: relative; - z-index: 1; - } - /* We put the background and clip-path in a separate element to prevent - popovers being clipped in the main element. */ - .patch-body::after { - position: absolute; - z-index: -1; - content: " "; - background-color: var(--color-background-float); - clip-path: var(--2px-corner-fill); - width: 100%; - height: 100%; - top: 0; - } .metadata-divider { width: 2px; background-color: var(--color-fill-ghost); @@ -492,15 +279,6 @@ margin-bottom: 0.5rem; color: var(--color-foreground-dim); } - .hide { - display: none; - } - .connector { - width: 2px; - height: 1rem; - margin-left: 1.25rem; - background-color: var(--color-background-float); - } @@ -599,8 +377,42 @@ {/if} + + -
+ + + + + + + + + +
- - { - tab = "revisions"; - }}> - {formatOid(revisions.slice(-1)[0].id)} - - Latest - - + {#if revisions.length > 1} + { + tab = "revisions"; + }}> + {formatOid(revisions.slice(-1)[0].id)} + + Latest + + + {/if}
@@ -647,163 +460,32 @@ styleDisplay="block" styleFlexDirection="column" styleAlignItems="flex-start"> -
- 1 - ? revisions[0].description.at(-1) - : undefined} - author={revisions[0].author} - reactions={revisions[0].reactions} - timestamp={revisions[0].timestamp} - body={revisions[0].description.slice(-1)[0].body} - reactOnComment={partial( - reactOnRevision, - config.publicKey, - revisions[0].id, - )} - editComment={roles.isDelegateOrAuthor( - config.publicKey, - repo.delegates.map(delegate => delegate.did), - revisions[0].author.did, - ) && partial(editRevision, revisions[0].id)}> - {#snippet actions()} - - {/snippet} - -
- - - - - - - - - - - - - -
- -
(hideDiscussion = !hideDiscussion)}> - Discussion -
-
- {#each threads as thread} - delegate.did), - )} - editComment={partial(editComment)} - createReply={partial(createReply)} - reactOnComment={partial(reactOnComment, config.publicKey)} /> -
- {/each} - -
- (topLevelReplyOpen = false) - : undefined} - placeholder="Leave a comment" - submit={partial(createComment)} /> -
-
-
- -
- -
(hideChanges = !hideChanges)}> - Changes -
-
- {#await loadHighlightedDiff(repo.rid, latestRevision.base, latestRevision.head)} - Loading… - {:then diff} - - {/await} -
-
- -
- -
(hideTimeline = !hideTimeline)}> - Timeline -
-
- -
-
+ {:else} - {@const revision = revisions.slice(-1)[0]} - {#await loadHighlightedDiff(repo.rid, revision.base, revision.head) then diff} - - {/await} + {/if}