Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Allow disabling of attachments in comments with reason
Thomas Scholtes committed 10 months ago
commit 686ca929643a3b120ec8405bddc2f943188b001b
parent d35920b8cbc94b0a73507a515b19779e37efc233
5 files changed +33 -12
modified src/components/Comment.svelte
@@ -35,7 +35,8 @@
    editComment?: (body: string, embeds: Embed[]) => Promise<void>;
    reactOnComment?: (authors: Author[], reaction: string) => Promise<void>;
    styleWidth?: string;
-
    allowAttachments?: boolean;
+
    // See `ExtendedTextarea`
+
    disableAttachments?: boolean | string;
  }

  /* eslint-disable prefer-const */
@@ -56,7 +57,7 @@
    reactOnComment,
    styleWidth,
    emptyBodyTooltip,
-
    allowAttachments = true,
+
    disableAttachments: disableAttachments,
  }: Props = $props();
  /* eslint-enable prefer-const */

@@ -195,7 +196,7 @@
            {embeds}
            {disallowEmptyBody}
            {emptyBodyTooltip}
-
            {allowAttachments}
+
            {disableAttachments}
            borderVariant="ghost"
            submitInProgress={state === "submit"}
            submitCaption="Save"
modified 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";
modified src/components/Diff.svelte
@@ -24,6 +24,8 @@
    ) => Promise<void>;
    // Defaults to `true`.
    canReply?: boolean;
+
    // See `ExtendedTextarea`.
+
    disableAttachments?: boolean | string;
    repoDelegates: Author[];
    rid: string;
    threads: Thread<CodeLocation>[];
@@ -504,6 +506,7 @@
                }}
                focus
                placeholder="Leave a comment"
+
                disableAttachments={codeComments.disableAttachments}
                submit={async (body, embeds) => {
                  if (selection?.codeLocation) {
                    try {
modified src/components/ExtendedTextarea.svelte
@@ -39,7 +39,11 @@
      embeds: Map<string, Embed>;
    }) => Promise<void>;
    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}
      <div
        class="txt-overflow txt-small txt-missing"
-
        title={`${allowAttachments ? "Drag and drop files to add them. " : ""}Markdown is supported. Press ${utils.modifierKey()}↵ to submit.`}>
-
        {#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}
        <Icon
          name="markdown"
          styleDisplay="inline"
@@ -294,8 +303,12 @@
      </div>
    {/if}
    <div class="buttons">
-
      {#if allowAttachments}
-
        <OutlineButton variant="ghost" onclick={selectFiles} disabled={preview}>
+
      {#if attachEnabled || attachDisabledReason}
+
        <OutlineButton
+
          variant="ghost"
+
          onclick={selectFiles}
+
          disabled={preview || attachDisabledReason !== undefined}
+
          title={attachDisabledReason}>
          <Icon name="attachment" />
          Attach
        </OutlineButton>
modified src/components/Review.svelte
@@ -365,7 +365,7 @@

    <div class="review-body">
      <CommentComponent
-
        allowAttachments={false}
+
        disableAttachments
        rid={repo.rid}
        disallowEmptyBody={review.verdict === undefined}
        emptyBodyTooltip="Summary is mandatory when verdict is None"