fix: save comment expand state

This commit is contained in:
Xylight committed 2024-09-01 13:22:22 -07:00
1 parent 4e4c351a9c
commit 1b5a9b1903
3 files changed
+30 -3

No files matched your search

@@ -26,6 +26,7 @@
import { t } from '$lib/translations'
import { slide } from 'svelte/transition'
import { expoInOut, expoOut } from 'svelte/easing'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
export let node: CommentNodeI
export let postId: number
@@ -110,8 +111,28 @@
>
<button
on:click={() => (open = !open)}
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full"
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full
z-0 group relative"
>
<div
class="absolute opacity-0 -z-10 inset-0 group-hover:block group-hover:opacity-100
bg-slate-100 dark:bg-zinc-900 group-hover:-inset-1 group-hover:-inset-x-2 rounded-full transition-all
"
>
<div
class="h-full flex items-center justify-center gap-1 ml-auto w-max mr-2"
>
{#if node.children.length > 0}
<FormattedNumber number={node.children.length}></FormattedNumber>
{/if}
<Icon
src={open ? Minus : Plus}
size="16"
micro
class="transition-transform duration-500 {open ? '' : 'rotate-90'}"
/>
</div>
</div>
<span class:font-bold={op} class="flex flex-row gap-1 items-center">
<UserLink
inComment
@@ -204,6 +225,7 @@
children: [],
comment_view: e.detail.comment_view,
depth: node.depth + 1,
ui: {},
},
...node.children,
]
@@ -116,7 +116,7 @@
<Comment
postId={post.id}
bind:node
open={true}
bind:open={node.ui.open}
op={post.creator_id == node.comment_view.creator.id}
>
{#if node.children?.length > 0}
@@ -125,7 +125,7 @@
{#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-2 border-slate-200 dark:border-zinc-800 pl-2 text-left"
class="w-full my-2 h-8 border-l border-slate-200 dark:border-zinc-800 pl-2 text-left"
href="/comment/{$page.params.instance}/{node.comment_view.comment.id}"
>
<Button
@@ -5,6 +5,9 @@ export interface CommentNodeI {
children: Array<CommentNodeI>
depth: number
loading?: boolean
ui: {
open?: boolean
}
}
function getCommentParentId(comment?: Comment): number | undefined {
@@ -38,6 +41,7 @@ export function buildCommentsTree(
comment_view,
children: [],
depth: depth,
ui: {},
}
min_depth = Math.min(min_depth, depth)
if (filter(comment_view)) {
@@ -103,6 +107,7 @@ export function insertCommentIntoTree(
comment_view: cv,
children: [],
depth: 0,
ui: {},
}
const parentId = getCommentParentId(cv.comment)