From 049b2b15df9ab2a26eaeba279b98c8249121b9d6 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 30 Jun 2025 13:21:16 +0200 Subject: [PATCH] Allow disabling of attachments in comments with reason [squash] Use shorthand property --- src/components/Comment.svelte | 7 +++--- src/components/CommentToggleInput.svelte | 4 ++++ src/components/Diff.svelte | 3 +++ src/components/ExtendedTextarea.svelte | 29 +++++++++++++++++------- src/components/Review.svelte | 2 +- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/components/Comment.svelte b/src/components/Comment.svelte index 9e4e47513..52df4c4b9 100644 --- a/src/components/Comment.svelte +++ b/src/components/Comment.svelte @@ -35,7 +35,8 @@ editComment?: (body: string, embeds: Embed[]) => Promise; reactOnComment?: (authors: Author[], reaction: string) => Promise; styleWidth?: string; - allowAttachments?: boolean; + // See `ExtendedTextarea` + disableAttachments?: boolean | string; } /* eslint-disable prefer-const */ @@ -56,7 +57,7 @@ reactOnComment, styleWidth, emptyBodyTooltip, - allowAttachments = true, + disableAttachments, }: Props = $props(); /* eslint-enable prefer-const */ @@ -195,7 +196,7 @@ {embeds} {disallowEmptyBody} {emptyBodyTooltip} - {allowAttachments} + {disableAttachments} borderVariant="ghost" submitInProgress={state === "submit"} submitCaption="Save" diff --git a/src/components/CommentToggleInput.svelte b/src/components/CommentToggleInput.svelte index 2c97ce742..6b64992c0 100644 --- a/src/components/CommentToggleInput.svelte +++ b/src/components/CommentToggleInput.svelte @@ -12,6 +12,8 @@ onclose?: () => void; onexpand?: () => void; disallowEmptyBody?: boolean; + // See `ExtendedTextarea` + disableAttachments?: boolean | string; } /* eslint-disable prefer-const */ @@ -23,6 +25,7 @@ onclose, onexpand, disallowEmptyBody = false, + disableAttachments, }: Props = $props(); /* eslint-enable prefer-const */ @@ -58,6 +61,7 @@ state = "collapsed"; } }} + {disableAttachments} submit={async ({ comment, embeds }) => { try { state = "submit"; diff --git a/src/components/Diff.svelte b/src/components/Diff.svelte index e6f574ced..4be56899b 100644 --- a/src/components/Diff.svelte +++ b/src/components/Diff.svelte @@ -24,6 +24,8 @@ ) => Promise; // Defaults to `true`. canReply?: boolean; + // See `ExtendedTextarea`. + disableAttachments?: boolean | string; repoDelegates: Author[]; rid: string; threads: Thread[]; @@ -504,6 +506,7 @@ }} focus placeholder="Leave a comment" + disableAttachments={codeComments.disableAttachments} submit={async (body, embeds) => { if (selection?.codeLocation) { try { diff --git a/src/components/ExtendedTextarea.svelte b/src/components/ExtendedTextarea.svelte index e427ee60d..ac75c269e 100644 --- a/src/components/ExtendedTextarea.svelte +++ b/src/components/ExtendedTextarea.svelte @@ -39,7 +39,11 @@ embeds: Map; }) => Promise; close: () => void; - allowAttachments?: boolean; + // If true, adding attachments through drag-and-drop is disabled and there + // is no "Attach" button. If a string is provided, the "Attach" button is + // visible but disabled and uses the string as the title to indicate the + // reason for disabling. Defaults to `false` + disableAttachments?: boolean | string; } /* eslint-disable prefer-const */ @@ -63,10 +67,15 @@ borderVariant = "float", submit, close, - allowAttachments = true, + disableAttachments: attachDisabled = false, }: Props = $props(); /* eslint-enable prefer-const */ + const attachEnabled = $derived(attachDisabled === false); + const attachDisabledReason = $derived( + typeof attachDisabled === "string" ? attachDisabled : undefined, + ); + let selectionStart = $state(body.length); let selectionEnd = $state(body.length); let draggingOver = $state(false); @@ -87,7 +96,7 @@ onMount(async () => { if (window.__TAURI_INTERNALS__) { - if (allowAttachments) { + if (attachEnabled) { dragEnterUnlistenFn = await listen("tauri://drag-enter", () => { draggingOver = true; }); @@ -149,7 +158,7 @@ } async function handlePaste(e: ClipboardEvent) { - if (!allowAttachments) { + if (!attachEnabled) { return; } @@ -284,8 +293,8 @@ {#if !preview}
- {#if allowAttachments}Drag and drop files to add them.{/if} + title={`${attachEnabled ? "Drag and drop files to add them. " : ""}Markdown is supported. Press ${utils.modifierKey()}↵ to submit.`}> + {#if attachEnabled}Drag and drop files to add them.{/if} {/if}
- {#if allowAttachments} - + {#if attachEnabled || attachDisabledReason} + Attach diff --git a/src/components/Review.svelte b/src/components/Review.svelte index 452eacc92..4b1fa6829 100644 --- a/src/components/Review.svelte +++ b/src/components/Review.svelte @@ -365,7 +365,7 @@