fix: comments not updating
This commit is contained in:
1 parent
714cb37a6e
commit
9970c8af6b
3 files changed
+141
-103
No files matched your search
@@ -16,13 +16,11 @@
|
|||||||
|
|
||||||
let { nodes, post, scrollTo }: Props = $props()
|
let { nodes, post, scrollTo }: Props = $props()
|
||||||
|
|
||||||
let nodesState = $state(nodes)
|
|
||||||
|
|
||||||
let virtualListEl = $state<HTMLElement>()
|
let virtualListEl = $state<HTMLElement>()
|
||||||
|
|
||||||
let virtualizer = $derived(
|
let virtualizer = $derived(
|
||||||
createWindowVirtualizer({
|
createWindowVirtualizer({
|
||||||
count: nodesState.length,
|
count: nodes.length,
|
||||||
estimateSize: () => 30,
|
estimateSize: () => 30,
|
||||||
scrollMargin: virtualListEl?.offsetTop,
|
scrollMargin: virtualListEl?.offsetTop,
|
||||||
initialRect: {
|
initialRect: {
|
||||||
@@ -73,7 +71,7 @@
|
|||||||
data-index={row.index}
|
data-index={row.index}
|
||||||
class="-mx-4 sm:-mx-6 px-4 sm:px-6"
|
class="-mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||||
>
|
>
|
||||||
<Comments isParent={true} nodes={[nodesState[row.index]]} {post} />
|
<Comments isParent={true} nodes={[nodes[row.index]]} {post} />
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
|
import CommentProvider from './CommentProvider.svelte'
|
||||||
|
|
||||||
let { data: loaded = $bindable() } = $props()
|
let { data: loaded = $bindable() } = $props()
|
||||||
let data = $state(loaded)
|
let data = $state(loaded)
|
||||||
@@ -395,105 +396,12 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:then comments}
|
{:then comments}
|
||||||
{#if $profile?.jwt}
|
<CommentProvider
|
||||||
{#if !commenting}
|
post={data.post}
|
||||||
<EndPlaceholder class="">
|
{comments}
|
||||||
<Button color="primary" onclick={() => (commenting = true)}>
|
focus={data.thread.focus}
|
||||||
<Icon src={PlusCircle} size="16" micro />
|
onupdate={reloadComments}
|
||||||
{$t('routes.post.addComment')}
|
bind:sort={commentSort}
|
||||||
</Button>
|
|
||||||
|
|
||||||
{#snippet action()}
|
|
||||||
<div class="gap-2 flex items-center">
|
|
||||||
<Select
|
|
||||||
size="md"
|
|
||||||
bind:value={commentSort}
|
|
||||||
onchange={reloadComments}
|
|
||||||
>
|
|
||||||
<Option icon={Fire} value="Hot">{$t('filter.sort.hot')}</Option>
|
|
||||||
<Option icon={Trophy} value="Top">
|
|
||||||
{$t('filter.sort.top.label')}
|
|
||||||
</Option>
|
|
||||||
<Option icon={Star} value="New">{$t('filter.sort.new')}</Option>
|
|
||||||
<Option icon={Clock} value="Old">
|
|
||||||
{$t('filter.sort.old')}
|
|
||||||
</Option>
|
|
||||||
<Option icon={ArrowTrendingDown} value="Controversial">
|
|
||||||
{$t('filter.sort.controversial')}
|
|
||||||
</Option>
|
|
||||||
</Select>
|
|
||||||
<Button size="square-md" onclick={reloadComments}>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon src={ArrowPath} size="16" mini />
|
|
||||||
{/snippet}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{/snippet}
|
|
||||||
</EndPlaceholder>
|
|
||||||
{:else}
|
|
||||||
<CommentForm
|
|
||||||
postId={data.post.post_view.post.id}
|
|
||||||
oncomment={(comment) => {
|
|
||||||
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}
|
|
||||||
<div class="gap-2 flex items-center">
|
|
||||||
<Select size="md" bind:value={commentSort} onchange={reloadComments}>
|
|
||||||
<Option icon={Fire} value="Hot">{$t('filter.sort.hot')}</Option>
|
|
||||||
<Option icon={Trophy} value="Top">
|
|
||||||
{$t('filter.sort.top.label')}
|
|
||||||
</Option>
|
|
||||||
<Option icon={Star} value="New">{$t('filter.sort.new')}</Option>
|
|
||||||
<Option icon={Clock} value="Old">
|
|
||||||
{$t('filter.sort.old')}
|
|
||||||
</Option>
|
|
||||||
<Option icon={ArrowTrendingDown} value="Controversial">
|
|
||||||
{$t('filter.sort.controversial')}
|
|
||||||
</Option>
|
|
||||||
</Select>
|
|
||||||
<Button size="square-md" onclick={reloadComments}>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon src={ArrowPath} size="16" mini />
|
|
||||||
{/snippet}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
<CommentListVirtualizer
|
|
||||||
post={data.post.post_view.post}
|
|
||||||
nodes={buildCommentsTree(
|
|
||||||
comments.comments,
|
|
||||||
undefined,
|
|
||||||
(c) =>
|
|
||||||
!(
|
|
||||||
(settings.hidePosts.deleted && c.comment.deleted) ||
|
|
||||||
(settings.hidePosts.removed && c.comment.removed)
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
scrollTo={data.thread.focus}
|
|
||||||
/>
|
/>
|
||||||
{#if comments.comments.length == 0}
|
{#if comments.comments.length == 0}
|
||||||
<Placeholder
|
<Placeholder
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
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))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if $profile?.jwt}
|
||||||
|
{#if !commenting}
|
||||||
|
<EndPlaceholder class="">
|
||||||
|
<Button color="primary" onclick={() => (commenting = true)}>
|
||||||
|
<Icon src={PlusCircle} size="16" micro />
|
||||||
|
{$t('routes.post.addComment')}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{#snippet action()}
|
||||||
|
<div class="gap-2 flex items-center">
|
||||||
|
<Select size="md" bind:value={sort} onchange={onupdate}>
|
||||||
|
<Option icon={Fire} value="Hot">{$t('filter.sort.hot')}</Option>
|
||||||
|
<Option icon={Trophy} value="Top">
|
||||||
|
{$t('filter.sort.top.label')}
|
||||||
|
</Option>
|
||||||
|
<Option icon={Star} value="New">{$t('filter.sort.new')}</Option>
|
||||||
|
<Option icon={Clock} value="Old">
|
||||||
|
{$t('filter.sort.old')}
|
||||||
|
</Option>
|
||||||
|
<Option icon={ArrowTrendingDown} value="Controversial">
|
||||||
|
{$t('filter.sort.controversial')}
|
||||||
|
</Option>
|
||||||
|
</Select>
|
||||||
|
<Button size="square-md" onclick={onupdate}>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={ArrowPath} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/snippet}
|
||||||
|
</EndPlaceholder>
|
||||||
|
{:else}
|
||||||
|
<CommentForm
|
||||||
|
postId={post.post_view.post.id}
|
||||||
|
oncomment={(comment) => {
|
||||||
|
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}
|
||||||
|
<div class="gap-2 flex items-center">
|
||||||
|
<Select size="md" bind:value={sort} onchange={onupdate}>
|
||||||
|
<Option icon={Fire} value="Hot">{$t('filter.sort.hot')}</Option>
|
||||||
|
<Option icon={Trophy} value="Top">
|
||||||
|
{$t('filter.sort.top.label')}
|
||||||
|
</Option>
|
||||||
|
<Option icon={Star} value="New">{$t('filter.sort.new')}</Option>
|
||||||
|
<Option icon={Clock} value="Old">
|
||||||
|
{$t('filter.sort.old')}
|
||||||
|
</Option>
|
||||||
|
<Option icon={ArrowTrendingDown} value="Controversial">
|
||||||
|
{$t('filter.sort.controversial')}
|
||||||
|
</Option>
|
||||||
|
</Select>
|
||||||
|
<Button size="square-md" onclick={onupdate}>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={ArrowPath} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
<CommentListVirtualizer
|
||||||
|
post={post.post_view.post}
|
||||||
|
nodes={tree}
|
||||||
|
scrollTo={focus}
|
||||||
|
/>
|
||||||
Reference in new issue
Block a user