design: a compact comment form until focused
This commit is contained in:
1 parent
32c4a060a1
commit
29432e0e15
4 files changed
+39
-24
No files matched your search
@@ -178,7 +178,9 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if replying}
|
{#if replying}
|
||||||
<div class="max-w-full my-2">
|
<div
|
||||||
|
class="max-w-full my-2 border-l border-slate-200 dark:border-zinc-800 pl-4"
|
||||||
|
>
|
||||||
<h1 class="font-bold text-sm mb-2">Reply</h1>
|
<h1 class="font-bold text-sm mb-2">Reply</h1>
|
||||||
<CommentForm
|
<CommentForm
|
||||||
{postId}
|
{postId}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
export let postId: number
|
export let postId: number
|
||||||
export let parentId: number | undefined = undefined
|
export let parentId: number | undefined = undefined
|
||||||
export let locked: boolean = false
|
export let locked: boolean = false
|
||||||
|
export let rows: number = 7
|
||||||
|
export let placeholder: string | undefined = undefined
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{ comment: CommentResponse }>()
|
const dispatch = createEventDispatcher<{ comment: CommentResponse }>()
|
||||||
|
|
||||||
@@ -64,10 +66,11 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
rows={7}
|
{...$$restProps}
|
||||||
|
{rows}
|
||||||
placeholder={locked
|
placeholder={locked
|
||||||
? 'This post is locked.'
|
? 'This post is locked.'
|
||||||
: placeholders.get('comment')}
|
: placeholder ?? placeholders.get('comment')}
|
||||||
bind:value
|
bind:value
|
||||||
disabled={locked || loading}
|
disabled={locked || loading}
|
||||||
on:confirm={() => {
|
on:confirm={() => {
|
||||||
@@ -75,7 +78,7 @@
|
|||||||
submit()
|
submit()
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:confirm
|
on:focus
|
||||||
previewButton={previewAction}
|
previewButton={previewAction}
|
||||||
>
|
>
|
||||||
{#if actions}
|
{#if actions}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
export let value: string = ''
|
export let value: string = ''
|
||||||
export let label: string | undefined = undefined
|
export let label: string | undefined = undefined
|
||||||
export let previewButton: boolean = false
|
export let previewButton: boolean = false
|
||||||
|
export let tools: boolean = true
|
||||||
export let disabled: boolean = false
|
export let disabled: boolean = false
|
||||||
export let rows: number = 4
|
export let rows: number = 4
|
||||||
|
|
||||||
@@ -62,7 +63,12 @@
|
|||||||
let uploadingImage = false
|
let uploadingImage = false
|
||||||
let loading = false
|
let loading = false
|
||||||
let image: any
|
let image: any
|
||||||
$: previewURL = image instanceof FileList ? URL.createObjectURL(image[0]) : image ? URL.createObjectURL(image) : ''
|
$: previewURL =
|
||||||
|
image instanceof FileList
|
||||||
|
? URL.createObjectURL(image[0])
|
||||||
|
: image
|
||||||
|
? URL.createObjectURL(image)
|
||||||
|
: ''
|
||||||
|
|
||||||
async function upload() {
|
async function upload() {
|
||||||
if (!$profile?.jwt || !image) return
|
if (!$profile?.jwt || !image) return
|
||||||
@@ -113,7 +119,8 @@
|
|||||||
border border-slate-300 dark:border-zinc-700 bg-white dark:bg-black
|
border border-slate-300 dark:border-zinc-700 bg-white dark:bg-black
|
||||||
cursor-pointer min-h-36 transition-colors
|
cursor-pointer min-h-36 transition-colors
|
||||||
"
|
"
|
||||||
on:drop|preventDefault={(event) => (image = event.dataTransfer?.files?.[0])}
|
on:drop|preventDefault={(event) =>
|
||||||
|
(image = event.dataTransfer?.files?.[0])}
|
||||||
on:dragover|preventDefault={(event) => {
|
on:dragover|preventDefault={(event) => {
|
||||||
if (event.dataTransfer) {
|
if (event.dataTransfer) {
|
||||||
event.dataTransfer.dropEffect = 'copy'
|
event.dataTransfer.dropEffect = 'copy'
|
||||||
@@ -133,7 +140,12 @@
|
|||||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||||
<p class="text-sm opacity-50">Attach a file</p>
|
<p class="text-sm opacity-50">Attach a file</p>
|
||||||
{/if}
|
{/if}
|
||||||
<input type="file" bind:files={image} accept="image/*" class="hidden" />
|
<input
|
||||||
|
type="file"
|
||||||
|
bind:files={image}
|
||||||
|
accept="image/*"
|
||||||
|
class="hidden"
|
||||||
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<Button {loading} disabled={loading} submit color="primary" size="lg">
|
<Button {loading} disabled={loading} submit color="primary" size="lg">
|
||||||
@@ -154,8 +166,10 @@
|
|||||||
</Label>
|
</Label>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="flex flex-col border border-slate-300 dark:border-zinc-800 rounded-xl
|
class="flex flex-col border border-slate-300 dark:border-zinc-800
|
||||||
overflow-hidden focus-within:border-black focus-within:dark:border-white transition-colors"
|
focus-within:border-primary-900 focus-within:dark:border-primary-100 focus-within:ring ring-slate-300
|
||||||
|
dark:ring-zinc-700 rounded-xl
|
||||||
|
overflow-hidden transition-colors"
|
||||||
class:mt-1={label}
|
class:mt-1={label}
|
||||||
>
|
>
|
||||||
{#if previewing}
|
{#if previewing}
|
||||||
@@ -165,6 +179,7 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
|||||||
<Markdown source={beforePreview(value)} />
|
<Markdown source={beforePreview(value)} />
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
{#if tools}
|
||||||
<!--Toolbar-->
|
<!--Toolbar-->
|
||||||
<div
|
<div
|
||||||
class="[&>*]:flex-shrink-0 flex flex-row overflow-auto p-1.5 gap-1.5 {$$props.disabled
|
class="[&>*]:flex-shrink-0 flex flex-row overflow-auto p-1.5 gap-1.5 {$$props.disabled
|
||||||
@@ -265,6 +280,7 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
|||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
<!--Actual text area-->
|
<!--Actual text area-->
|
||||||
<TextArea
|
<TextArea
|
||||||
class="bg-inherit z-0 border-0 rounded-none !ring-0 focus:!ring-transparent !transition-none"
|
class="bg-inherit z-0 border-0 rounded-none !ring-0 focus:!ring-transparent !transition-none"
|
||||||
@@ -281,6 +297,7 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
on:focus
|
||||||
on:paste={(e) => {
|
on:paste={(e) => {
|
||||||
if (!e.clipboardData?.files) return
|
if (!e.clipboardData?.files) return
|
||||||
const files = Array.from(e.clipboardData.files)
|
const files = Array.from(e.clipboardData.files)
|
||||||
@@ -294,7 +311,7 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $$slots.default || previewButton}
|
{#if $$slots.default && previewButton}
|
||||||
<div class="p-2 flex items-center w-full bg-white dark:bg-zinc-950">
|
<div class="p-2 flex items-center w-full bg-white dark:bg-zinc-950">
|
||||||
{#if previewButton}
|
{#if previewButton}
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
|
|||||||
@@ -143,7 +143,7 @@
|
|||||||
commentsPage = 1
|
commentsPage = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
let showCreateComment = false
|
let commenting = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -288,7 +288,7 @@ flex-wrap gap-4 sticky top-20 w-full box-border z-20 mt-4"
|
|||||||
You're viewing a single thread.
|
You're viewing a single thread.
|
||||||
</p>
|
</p>
|
||||||
<Button {loading} disabled={loading} on:click={reloadComments}>
|
<Button {loading} disabled={loading} on:click={reloadComments}>
|
||||||
View all comments
|
All comments
|
||||||
</Button>
|
</Button>
|
||||||
</Material>
|
</Material>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -321,7 +321,6 @@ flex-wrap gap-4 sticky top-20 w-full box-border z-20 mt-4"
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if $profile?.user}
|
{#if $profile?.user}
|
||||||
{#if showCreateComment}
|
|
||||||
<CommentForm
|
<CommentForm
|
||||||
postId={post.post_view.post.id}
|
postId={post.post_view.post.id}
|
||||||
on:comment={(comment) =>
|
on:comment={(comment) =>
|
||||||
@@ -331,18 +330,12 @@ flex-wrap gap-4 sticky top-20 w-full box-border z-20 mt-4"
|
|||||||
])}
|
])}
|
||||||
locked={post.post_view.post.locked ||
|
locked={post.post_view.post.locked ||
|
||||||
$page.params.instance.toLowerCase() != $instance.toLowerCase()}
|
$page.params.instance.toLowerCase() != $instance.toLowerCase()}
|
||||||
|
on:focus={() => (commenting = true)}
|
||||||
|
tools={commenting}
|
||||||
|
preview={commenting}
|
||||||
|
placeholder={commenting ? undefined : 'Add a comment'}
|
||||||
|
rows={commenting ? 7 : 1}
|
||||||
/>
|
/>
|
||||||
{:else}
|
|
||||||
<Button
|
|
||||||
on:click={() => (showCreateComment = !showCreateComment)}
|
|
||||||
size="lg"
|
|
||||||
rounding="lg"
|
|
||||||
class="mx-auto max-w-sm w-full"
|
|
||||||
>
|
|
||||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
|
||||||
Add a comment
|
|
||||||
</Button>
|
|
||||||
{/if}
|
|
||||||
{/if}
|
{/if}
|
||||||
<Comments
|
<Comments
|
||||||
post={post.post_view.post}
|
post={post.post_view.post}
|
||||||
|
|||||||
Reference in new issue
Block a user