From 921b8f12150d3c1486cf24ed59b70877f7350c19 Mon Sep 17 00:00:00 2001 From: Xylight Date: Mon, 21 Oct 2024 19:13:55 -0700 Subject: [PATCH] design: redesign comment threads --- .../components/lemmy/comment/Comment.svelte | 75 ++++++++++--------- .../comment/CommentListVirtualizer.svelte | 17 ++++- .../components/lemmy/comment/Comments.svelte | 35 ++++++--- 3 files changed, 82 insertions(+), 45 deletions(-) diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 8e04235d..f5c6cd91 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -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 @@ @@ -189,7 +193,10 @@ {/if} {#if open} -
+
{#if actions} -
- (editing = true)} - disabled={node.comment_view.banned_from_community || - node.comment_view.post.locked} - /> -
+ (editing = true)} + disabled={node.comment_view.banned_from_community || + node.comment_view.post.locked} + /> {/if}
{#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 }} > -
- {$t('comment.reply')} +
+ { + node.children = [ + { + children: [], + comment_view: e.detail.comment_view, + depth: node.depth + 1, + ui: {}, + }, + ...node.children, + ] + replying = false + }} + on:cancel={() => (replying = false)} + />
- { - node.children = [ - { - children: [], - comment_view: e.detail.comment_view, - depth: node.depth + 1, - ui: {}, - }, - ...node.children, - ] - replying = false - }} - on:cancel={() => (replying = false)} - />
{/if} -
- -
+ {#if childrenOpen} +
+ +
+ {/if}
{/if} diff --git a/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte b/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte index ddeb472d..17ab52ea 100644 --- a/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte +++ b/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte @@ -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) + } + })
{#each items as row, index (row.index)} -
+
{/each} diff --git a/src/lib/components/lemmy/comment/Comments.svelte b/src/lib/components/lemmy/comment/Comments.svelte index 93146b73..0187652a 100644 --- a/src/lib/components/lemmy/comment/Comments.svelte +++ b/src/lib/components/lemmy/comment/Comments.svelte @@ -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)} {#if node.children?.length > 0} @@ -125,22 +130,34 @@ {#if node.comment_view.counts.child_count > 0 && node.children.length == 0}