diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index bcb1d3d1..51d92660 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -8,14 +8,14 @@ Plus, Trash, } from 'svelte-hero-icons' - import type { CommentNodeI } from './comments' + import { insertCommentIntoTree, type CommentNodeI } from './comments' import RelativeDate from '$lib/components/util/RelativeDate.svelte' import CommentForm from './CommentForm.svelte' import { page } from '$app/stores' import UserLink from '$lib/components/lemmy/user/UserLink.svelte' import Markdown from '$lib/components/markdown/Markdown.svelte' import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte' - import { createEventDispatcher } from 'svelte' + import { createEventDispatcher, getContext } from 'svelte' import type { CommentView } from 'lemmy-js-client' import Modal from '$lib/components/ui/modal/Modal.svelte' import { authData, getClient } from '$lib/lemmy.js' @@ -163,14 +163,11 @@ {postId} parentId={node.comment_view.comment.id} on:comment={(e) => { - node.children = [ - { - children: [], - depth: node.depth + 1, - comment_view: e.detail.comment_view, - }, - ...node.children, - ] + insertCommentIntoTree( + getContext('comments:tree'), + e.detail.comment_view, + false + ) replying = false }} /> diff --git a/src/lib/components/lemmy/comment/Comments.svelte b/src/lib/components/lemmy/comment/Comments.svelte index 3ecfd3d8..76a5544a 100644 --- a/src/lib/components/lemmy/comment/Comments.svelte +++ b/src/lib/components/lemmy/comment/Comments.svelte @@ -2,7 +2,7 @@ import Comment from './Comment.svelte' import { buildCommentsTree, type CommentNodeI } from './comments' import { page } from '$app/stores' - import { onMount } from 'svelte' + import { onMount, setContext } from 'svelte' import Button from '$lib/components/input/Button.svelte' import { ChevronDown, Icon } from 'svelte-hero-icons' import { authData, getClient } from '$lib/lemmy.js' @@ -14,6 +14,10 @@ export let isParent: boolean export let post: Post + if (isParent) { + setContext('comments:tree', nodes) + } + onMount(() => { if (isParent && $page.url.hash) { document.getElementById($page.url.hash)?.scrollIntoView({ diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte index 6b347dbe..ab1623f2 100644 --- a/src/routes/post/[instance]/[id]/+page.svelte +++ b/src/routes/post/[instance]/[id]/+page.svelte @@ -139,7 +139,7 @@ {#if post.body}