feat: add cancel button to commentform

This commit is contained in:
Xylight committed 2024-09-06 15:17:38 -07:00
1 parent 34300a5bdf
commit 815a6d2385
5 files changed
+33 -18

No files matched your search

@@ -218,7 +218,9 @@
class="max-w-full my-2 border-l border-slate-200 dark:border-zinc-800 pl-4" class="max-w-full my-2 border-l border-slate-200 dark:border-zinc-800 pl-4"
transition:slide={{ axis: 'y', duration: 400, easing: expoOut }} transition:slide={{ axis: 'y', duration: 400, easing: expoOut }}
> >
<h1 class="font-bold text-sm mb-2">{$t('comment.reply')}</h1> <div class="font-medium text-sm mb-2">
{$t('comment.reply')}
</div>
<CommentForm <CommentForm
{postId} {postId}
parentId={node.comment_view.comment.id} parentId={node.comment_view.comment.id}
@@ -234,6 +236,7 @@
] ]
replying = false replying = false
}} }}
on:cancel={() => (replying = false)}
/> />
</div> </div>
{/if} {/if}
@@ -9,6 +9,7 @@
import { placeholders } from '$lib/util.js' import { placeholders } from '$lib/util.js'
import { Button } from 'mono-svelte' import { Button } from 'mono-svelte'
import { t } from '$lib/translations' import { t } from '$lib/translations'
import { errorMessage } from '$lib/lemmy/error'
export let postId: number export let postId: number
export let parentId: number | undefined = undefined export let parentId: number | undefined = undefined
@@ -20,6 +21,7 @@
const dispatch = createEventDispatcher<{ const dispatch = createEventDispatcher<{
comment: CommentResponse comment: CommentResponse
confirm: string confirm: string
cancel: boolean
}>() }>()
export let value = '' export let value = ''
@@ -48,7 +50,7 @@
} catch (err) { } catch (err) {
console.error(err) console.error(err)
toast({ toast({
content: err as any, content: errorMessage(err as any),
type: 'error', type: 'error',
}) })
} }
@@ -73,7 +75,7 @@
? $t('comment.locked') ? $t('comment.locked')
: banned : banned
? $t('comment.banned') ? $t('comment.banned')
: placeholder ?? placeholders.get('comment')} : (placeholder ?? placeholders.get('comment'))}
bind:value bind:value
disabled={locked || loading || banned} disabled={locked || loading || banned}
on:confirm={() => { on:confirm={() => {
@@ -85,20 +87,26 @@
on:focus on:focus
previewButton={previewAction} previewButton={previewAction}
> >
<div class="flex-1" />
{#if actions} {#if actions}
<div class="ml-auto"> <Button
<Button on:click={() => dispatch('cancel', true)}
large color="tertiary"
on:click={submit} size="lg"
color="primary" class=" w-28"
size="lg" >
class="sm:ml-auto w-28" {$t('common.cancel')}
{loading} </Button>
disabled={locked || loading || banned} <Button
> on:click={submit}
{$t('form.submit')} color="primary"
</Button> size="lg"
</div> class=" w-28"
{loading}
disabled={locked || loading || banned}
>
{$t('form.submit')}
</Button>
{/if} {/if}
</MarkdownEditor> </MarkdownEditor>
{/if} {/if}
@@ -23,7 +23,7 @@
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900" class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
data-sveltekit-preload-data="off" data-sveltekit-preload-data="off"
aria-label={post.name} aria-label={post.name}
on:click={() => showImage(bestImageURL(post, false, 2048))} on:click={() => showImage(bestImageURL(post, false, -1))}
role="button" role="button"
tabindex="0" tabindex="0"
> >
@@ -256,7 +256,9 @@ overflow-hidden transition-colors {$$props.class}"
{/if} {/if}
{#if previewButton} {#if previewButton}
<div class="p-2 flex items-center w-full bg-white dark:bg-zinc-950"> <div
class="p-2 flex flex-row items-center w-full bg-white dark:bg-zinc-950 gap-1"
>
{#if previewButton} {#if previewButton}
<MultiSelect <MultiSelect
bind:selected={previewing} bind:selected={previewing}
@@ -218,6 +218,7 @@
type={mediaType(post.post_view.post.url)} type={mediaType(post.post_view.post.url)}
post={post.post_view.post} post={post.post_view.post}
opened opened
view="cozy"
/> />
{#if post.post_view.post.body} {#if post.post_view.post.body}
<div class="text-base text-slate-800 dark:text-zinc-300 leading-[1.5]"> <div class="text-base text-slate-800 dark:text-zinc-300 leading-[1.5]">
@@ -356,6 +357,7 @@
preview={commenting} preview={commenting}
placeholder={commenting ? undefined : $t('routes.post.addComment')} placeholder={commenting ? undefined : $t('routes.post.addComment')}
rows={commenting ? 7 : 1} rows={commenting ? 7 : 1}
on:cancel={() => (commenting = false)}
/> />
{/if} {/if}
{/if} {/if}