Skip to content

Commit

Permalink
Allow preview for empty body in ExtendedTextarea
Browse files Browse the repository at this point in the history
Instead of disabling the preview feature when the body is empty, we show
`Nothing to preview`
  • Loading branch information
sebastinez committed Dec 18, 2024
1 parent d6d9c43 commit fe7a885
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
3 changes: 0 additions & 3 deletions src/components/Comment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
caption?: string;
timestamp: number;
lastEdit?: Edit;
disallowEmptyBody?: boolean;
editComment?: (body: string, embeds: Embed[]) => Promise<void>;
reactOnComment?: (authors: Author[], reaction: string) => Promise<void>;
}
Expand All @@ -46,7 +45,6 @@
caption = "commented",
timestamp,
lastEdit,
disallowEmptyBody = false,
editComment,
reactOnComment,
}: Props = $props();
Expand Down Expand Up @@ -180,7 +178,6 @@
{body}
{rid}
{embeds}
{disallowEmptyBody}
borderVariant="ghost"
submitInProgress={state === "submit"}
submitCaption="Save"
Expand Down
3 changes: 0 additions & 3 deletions src/components/CommentToggleInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
submit: (comment: string, embeds: Embed[]) => Promise<void>;
onclose?: () => void;
onexpand?: () => void;
disallowEmptyBody?: boolean;
}
/* eslint-disable prefer-const */
Expand All @@ -22,7 +21,6 @@
submit,
onclose,
onexpand,
disallowEmptyBody = false,
}: Props = $props();
/* eslint-enable prefer-const */
Expand All @@ -43,7 +41,6 @@

{#if state !== "collapsed"}
<ExtendedTextarea
{disallowEmptyBody}
{rid}
{placeholder}
submitInProgress={state === "submit"}
Expand Down
18 changes: 7 additions & 11 deletions src/components/ExtendedTextarea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
embeds?: Map<string, Embed>;
submitInProgress?: boolean;
disableSubmit?: boolean;
disallowEmptyBody?: boolean;
isValid?: () => boolean;
preview?: boolean;
stylePadding?: string;
Expand All @@ -54,7 +53,6 @@
embeds = new Map(),
submitInProgress = false,
disableSubmit = false,
disallowEmptyBody = false,
isValid = () => true,
stylePadding,
borderVariant = "float",
Expand Down Expand Up @@ -238,7 +236,11 @@
<div class="comment-section" aria-label="extended-textarea" class:inline>
{#if preview}
<div class="preview">
<Markdown {rid} breaks content={body} />
{#if body.trim().length === 0}
<span class="txt-missing">Nothing to preview.</span>
{:else}
<Markdown {rid} breaks content={body} />
{/if}
</div>
{:else}
<Textarea
Expand Down Expand Up @@ -282,19 +284,13 @@
<Icon name="attachment" />
Attach
</OutlineButton>
<OutlineButton
variant="ghost"
disabled={body.trim() === ""}
onclick={() => (preview = !preview)}>
<OutlineButton variant="ghost" onclick={() => (preview = !preview)}>
<Icon name={preview ? "pen" : "eye"} />
{preview ? "Edit" : "Preview"}
</OutlineButton>
<Button
variant="ghost"
disabled={!isValid() ||
submitInProgress ||
disableSubmit ||
(disallowEmptyBody && body.trim() === "")}
disabled={!isValid() || submitInProgress || disableSubmit}
onclick={submitFn}>
<Icon name="checkmark" />
{#if submitInProgress}
Expand Down
3 changes: 0 additions & 3 deletions src/components/Thread.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
<div class="comments" {style}>
<div class="top-level-comment">
<CommentComponent
disallowEmptyBody
{rid}
id={root.id}
lastEdit={root.edits.length > 1 ? root.edits.at(-1) : undefined}
Expand All @@ -121,7 +120,6 @@
{#if replies.length > 0}
{#each replies as reply}
<CommentComponent
disallowEmptyBody
{rid}
lastEdit={reply.edits.length > 1 ? reply.edits.at(-1) : undefined}
id={reply.id}
Expand All @@ -140,7 +138,6 @@
{#if createReply && showReplyForm}
<div id={`reply-${root.id}`} style:padding="1rem">
<ExtendedTextarea
disallowEmptyBody
{submitInProgress}
{rid}
inline
Expand Down
7 changes: 5 additions & 2 deletions src/views/repo/CreateIssue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
<div class="content">
{#if preview}
<div class="title">
<InlineTitle content={title} fontSize="medium" />
{#if title.trim().length === 0}
<span class="txt-missing">No title</span>
{:else}
<InlineTitle content={title} fontSize="medium" />
{/if}
</div>
{:else}
<div style:margin-bottom="0.35rem">
Expand Down Expand Up @@ -138,7 +142,6 @@
<ExtendedTextarea
textAreaSize="fixed-height"
disableSubmit={title.trim() === ""}
disallowEmptyBody
submitCaption="Save"
close={() => window.history.back()}
submit={async ({ comment, embeds }) => {
Expand Down
1 change: 0 additions & 1 deletion src/views/repo/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@

<div id={`reply-${issue.id}`}>
<CommentToggleInput
disallowEmptyBody
rid={repo.rid}
focus={focusReply}
onexpand={toggleReply}
Expand Down

0 comments on commit fe7a885

Please sign in to comment.