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
+82 -45

No files matched your search

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