diff --git a/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte b/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte index 15c7acdd..ec04a8e7 100644 --- a/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte +++ b/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte @@ -16,13 +16,11 @@ let { nodes, post, scrollTo }: Props = $props() - let nodesState = $state(nodes) - let virtualListEl = $state() let virtualizer = $derived( createWindowVirtualizer({ - count: nodesState.length, + count: nodes.length, estimateSize: () => 30, scrollMargin: virtualListEl?.offsetTop, initialRect: { @@ -73,7 +71,7 @@ data-index={row.index} class="-mx-4 sm:-mx-6 px-4 sm:px-6" > - + {/each} diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index 9309c8a0..a819386f 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -53,6 +53,7 @@ import { fly } from 'svelte/transition' import { expoOut } from 'svelte/easing' import Option from 'mono-svelte/forms/select/Option.svelte' + import CommentProvider from './CommentProvider.svelte' let { data: loaded = $bindable() } = $props() let data = $state(loaded) @@ -395,105 +396,12 @@ {/each} {:then comments} - {#if $profile?.jwt} - {#if !commenting} - - - - {#snippet action()} -
- - -
- {/snippet} -
- {:else} - { - Promise.resolve(data.comments).then((r) => { - r.comments.push(comment.comment_view) - }) - // comments.comments.push(comment.comment_view) - // reloadComments() - // toast({ content: $t('routes.post.commented'), type: 'success' }) - }} - locked={(data.post.post_view.post.locked && - !( - $profile?.user?.local_user_view.local_user.admin || - $profile?.user?.moderates - .map((c) => c.community.id) - .includes(data.post.community_view.community.id) - )) || - page.params.instance.toLowerCase() != $instance.toLowerCase()} - banned={data.post.community_view.banned_from_community} - onfocus={() => (commenting = true)} - tools={commenting} - preview={commenting} - placeholder={commenting ? undefined : $t('routes.post.addComment')} - rows={commenting ? 7 : 1} - oncancel={() => (commenting = false)} - /> - {/if} - {/if} - - {#if commenting || !$profile.jwt} -
- - -
- {/if} - - !( - (settings.hidePosts.deleted && c.comment.deleted) || - (settings.hidePosts.removed && c.comment.removed) - ), - )} - scrollTo={data.thread.focus} + {#if comments.comments.length == 0} + import { page } from '$app/state' + import { profile } from '$lib/auth.svelte' + import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte' + import CommentListVirtualizer from '$lib/components/lemmy/comment/CommentListVirtualizer.svelte' + import { buildCommentsTree } from '$lib/components/lemmy/comment/comments.svelte' + import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte' + import { instance } from '$lib/instance' + import { settings } from '$lib/settings.svelte' + import { t } from '$lib/translations' + import type { + CommentSortType, + GetCommentsResponse, + GetPostResponse, + PostView, + } from 'lemmy-js-client' + import { Button, Option, Select } from 'mono-svelte' + import { + ArrowPath, + ArrowTrendingDown, + Clock, + Fire, + Icon, + PlusCircle, + Star, + Trophy, + } from 'svelte-hero-icons' + + interface Props { + post: GetPostResponse + comments: GetCommentsResponse + sort?: CommentSortType + onupdate?: () => void + focus?: string + } + + let { + post, + comments: passedComments, + sort = $bindable(), + onupdate, + focus, + }: Props = $props() + let comments = $state(passedComments) + + let commenting = $state(false) + let tree = $derived(buildCommentsTree(comments.comments)) + + +{#if $profile?.jwt} + {#if !commenting} + + + + {#snippet action()} +
+ + +
+ {/snippet} +
+ {:else} + { + comments.comments = [comment.comment_view, ...comments.comments] + }} + locked={(post.post_view.post.locked && + !( + $profile?.user?.local_user_view.local_user.admin || + $profile?.user?.moderates + .map((c) => c.community.id) + .includes(post.community_view.community.id) + )) || + page.params.instance.toLowerCase() != $instance.toLowerCase()} + banned={post.community_view.banned_from_community} + onfocus={() => (commenting = true)} + tools={commenting} + preview={commenting} + placeholder={commenting ? undefined : $t('routes.post.addComment')} + rows={commenting ? 7 : 1} + oncancel={() => (commenting = false)} + /> + {/if} +{/if} + +{#if commenting || !$profile.jwt} +
+ + +
+{/if} +