design: redesign comment threads

This commit is contained in:
Xylight committed 2024-10-21 19:13:55 -07:00
1 parent 643221e89d
commit 921b8f1215
3 files changed
+54 -17

No files matched your search

@@ -8,6 +8,8 @@
Pencil, Pencil,
Plus, Plus,
Trash, Trash,
PlusCircle,
MinusCircle,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import type { CommentNodeI } from './comments' import type { CommentNodeI } from './comments'
import RelativeDate from '$lib/components/util/RelativeDate.svelte' import RelativeDate from '$lib/components/util/RelativeDate.svelte'
@@ -24,7 +26,7 @@
import { page } from '$app/stores' import { page } from '$app/stores'
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { t } from '$lib/translations' import { t } from '$lib/translations'
import { slide } from 'svelte/transition' import { fly, slide } from 'svelte/transition'
import { expoInOut, expoOut } from 'svelte/easing' import { expoInOut, expoOut } from 'svelte/easing'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
@@ -36,6 +38,8 @@
export let meta: boolean = true export let meta: boolean = true
export let open = true export let open = true
let childrenOpen = true
export let replying = false export let replying = false
let editing = false let editing = false
@@ -142,7 +146,7 @@
<span class:font-bold={op} class="flex flex-row gap-1 items-center"> <span class:font-bold={op} class="flex flex-row gap-1 items-center">
<UserLink <UserLink
inComment inComment
avatarSize={22} avatarSize={24}
avatar avatar
user={node.comment_view.creator} user={node.comment_view.creator}
> >
@@ -189,7 +193,10 @@
</button> </button>
{/if} {/if}
{#if open} {#if open}
<div transition:slide={{ duration: 400, easing: expoOut }}> <div
class="relative {$$props.contentClass}"
transition:slide={{ duration: 400, easing: expoOut }}
>
<div <div
class="flex flex-col whitespace-pre-wrap class="flex flex-col whitespace-pre-wrap
max-w-full gap-1 mt-1 relative" max-w-full gap-1 mt-1 relative"
@@ -206,7 +213,6 @@
<Markdown source={node.comment_view.comment.content} /> <Markdown source={node.comment_view.comment.content} />
</div> </div>
{#if actions} {#if actions}
<div class="flex flex-row gap-2 items-center">
<CommentActions <CommentActions
bind:comment={node.comment_view} bind:comment={node.comment_view}
bind:replying bind:replying
@@ -214,7 +220,6 @@
disabled={node.comment_view.banned_from_community || disabled={node.comment_view.banned_from_community ||
node.comment_view.post.locked} node.comment_view.post.locked}
/> />
</div>
{/if} {/if}
</div> </div>
{#if replying} {#if replying}
@@ -222,10 +227,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 }}
> >
<div class="font-medium text-sm mb-2"> <div in:fly={{ duration: 500, y: -16, easing: expoOut, delay: 200 }}>
{$t('comment.reply')}
</div>
<CommentForm <CommentForm
label={$t('comment.reply')}
{postId} {postId}
parentId={node.comment_view.comment.id} parentId={node.comment_view.comment.id}
on:comment={(e) => { on:comment={(e) => {
@@ -243,10 +247,13 @@
on:cancel={() => (replying = false)} on:cancel={() => (replying = false)}
/> />
</div> </div>
</div>
{/if} {/if}
{#if childrenOpen}
<div class="bg-transparent dark:bg-transparent"> <div class="bg-transparent dark:bg-transparent">
<slot /> <slot />
</div> </div>
{/if}
</div> </div>
{/if} {/if}
</li> </li>
@@ -31,6 +31,15 @@
if (virtualItemEls.length) if (virtualItemEls.length)
virtualItemEls.forEach((el) => $virtualizer.measureElement(el)) virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
} }
onMount(() => {
if (scrollTo) {
const element = document?.getElementById(scrollTo)
setTimeout(() => {
element?.scrollIntoView({ behavior: 'smooth', block: 'start' })
}, 100)
}
})
</script> </script>
<div <div
@@ -43,11 +52,15 @@
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0] style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0]
? items?.[0]?.start - $virtualizer.options.scrollMargin ? items?.[0]?.start - $virtualizer.options.scrollMargin
: 0}px);" : 0}px);"
class="divide-y divide-slate-200 dark:divide-zinc-800" class="divide-y divide-slate-200 dark:divide-zinc-900"
id="feed" id="feed"
> >
{#each items as row, index (row.index)} {#each items as row, index (row.index)}
<div bind:this={virtualItemEls[index]} data-index={row.index}> <div
bind:this={virtualItemEls[index]}
data-index={row.index}
class="-mx-4 sm:-mx-6 px-4 sm:px-6"
>
<Comments isParent={true} nodes={[nodes[row.index]]} {post} /> <Comments isParent={true} nodes={[nodes[row.index]]} {post} />
</div> </div>
{/each} {/each}
@@ -9,6 +9,7 @@
Icon, Icon,
Plus, Plus,
PlusCircle, PlusCircle,
ArrowDownCircle,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import type { CommentView, Post } from 'lemmy-js-client' import type { CommentView, Post } from 'lemmy-js-client'
@@ -16,7 +17,7 @@
import { toast } from 'mono-svelte' import { toast } from 'mono-svelte'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { Button } from 'mono-svelte' import { Button } from 'mono-svelte'
import { afterNavigate } from '$app/navigation' import { afterNavigate, goto } from '$app/navigation'
import { backOut, expoOut } from 'svelte/easing' import { backOut, expoOut } from 'svelte/easing'
import { t } from '$lib/translations' import { t } from '$lib/translations'
import { browser } from '$app/environment' import { browser } from '$app/environment'
@@ -110,7 +111,7 @@
in:fly={{ duration: 500, easing: expoOut, y: -12 }} in:fly={{ duration: 500, easing: expoOut, y: -12 }}
class={isParent class={isParent
? 'divide-y dark:divide-zinc-900 divide-slate-100' ? 'divide-y dark:divide-zinc-900 divide-slate-100'
: 'pl-3.5 border-l border-slate-200 dark:border-zinc-800 my-1'} : ' border-slate-200 dark:border-zinc-800 my-1'}
> >
{#each nodes as node (node.comment_view.comment.id)} {#each nodes as node (node.comment_view.comment.id)}
<Comment <Comment
@@ -118,6 +119,10 @@
bind:node bind:node
bind:open={node.ui.open} bind:open={node.ui.open}
op={post.creator_id == node.comment_view.creator.id} op={post.creator_id == node.comment_view.creator.id}
contentClass="pl-3 {node.children.length > 0 ||
node.comment_view.counts.child_count > 0
? 'border-l'
: ''} ml-3 border-slate-200 dark:border-zinc-800"
> >
{#if node.children?.length > 0} {#if node.children?.length > 0}
<svelte:self {post} bind:nodes={node.children} isParent={false} /> <svelte:self {post} bind:nodes={node.children} isParent={false} />
@@ -125,22 +130,34 @@
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0} {#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
<svelte:element <svelte:element
this={hydrated ? 'div' : 'a'} this={hydrated ? 'div' : 'a'}
class="w-full my-2 h-8 border-l border-slate-200 dark:border-zinc-800 pl-2 text-left" class="w-full my-2 h-8"
href="/comment/{$page.params.instance}/{node.comment_view.comment.id}" href="/comment/{$page.params.instance}/{node.comment_view.comment.id}"
> >
<Button <Button
loading={node.loading} loading={node.loading}
disabled={node.loading} disabled={node.loading}
size="sm" rounding="pill"
color="tertiary" color="tertiary"
alignment="left" class="font-normal text-slate-600 dark:text-zinc-400"
class="font-normal" loaderWidth={16}
on:click={() => { on:click={() => {
if (node.depth > 7) {
goto(
`/comment/${$page.params.instance}/${node.comment_view.comment.id}#comments`
)
} else {
node.loading = true node.loading = true
fetchChildren(node).then(() => (node.loading = false)) fetchChildren(node).then(() => (node.loading = false))
}
}} }}
> >
<Icon src={ChevronDoubleDown} micro size="16" slot="prefix" /> <Icon
src={ArrowDownCircle}
micro
size="16"
slot="prefix"
class="text-primary-900 dark:text-primary-100"
/>
{$t('comment.more', { {$t('comment.more', {
// @ts-ignore // @ts-ignore
comments: node.comment_view.counts.child_count, comments: node.comment_view.counts.child_count,