fix: Make child loading indicator only appear on parent
This commit is contained in:
1 parent
4c3b5fae6a
commit
0fb17f626f
4 files changed
+32
-22
No files matched your search
@@ -8,6 +8,7 @@
|
|||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
import { toast, ToastType } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
export let nodes: CommentNodeI[]
|
||||||
export let isParent: boolean
|
export let isParent: boolean
|
||||||
@@ -33,26 +34,31 @@
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
loadingChildren = true
|
try {
|
||||||
|
parent.loading = true
|
||||||
|
|
||||||
const newComments = await getClient().getComments({
|
const newComments = await getClient().getComments({
|
||||||
auth: $authData?.token,
|
auth: $authData?.token,
|
||||||
max_depth: 5,
|
max_depth: 5,
|
||||||
parent_id: parent.comment_view.comment.id,
|
parent_id: parent.comment_view.comment.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (newComments.comments.length == 0) {
|
if (newComments.comments.length == 0) {
|
||||||
loadingChildren = false
|
loadingChildren = false
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// this code sucks, but for some reason it works
|
||||||
|
// lemmy api is quite goofy
|
||||||
|
parent.children = buildCommentsTree(newComments.comments, true).find(
|
||||||
|
(c) => c.comment_view.comment.id == parent.comment_view.comment.id
|
||||||
|
)!.children
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
content: 'Failed to fetch comments',
|
||||||
|
type: ToastType.error,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// this code sucks, but for some reason it works
|
|
||||||
// lemmy api is quite goofy
|
|
||||||
parent.children = buildCommentsTree(newComments.comments, true).find(
|
|
||||||
(c) => c.comment_view.comment.id == parent.comment_view.comment.id
|
|
||||||
)!.children
|
|
||||||
|
|
||||||
loadingChildren = false
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -77,9 +83,12 @@
|
|||||||
class="my-2 min-w-[7rem] w-max h-8 border-l-2 border-slate-200 dark:border-zinc-900 ml-2.5 pl-0.5"
|
class="my-2 min-w-[7rem] w-max h-8 border-l-2 border-slate-200 dark:border-zinc-900 ml-2.5 pl-0.5"
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
loading={loadingChildren}
|
loading={node.loading}
|
||||||
disabled={loadingChildren}
|
disabled={node.loading}
|
||||||
on:click={() => fetchChildren(node)}
|
on:click={() => {
|
||||||
|
node.loading = true
|
||||||
|
fetchChildren(node).then(() => (node.loading = false))
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Icon src={ChevronDown} width={16} mini slot="icon" />
|
<Icon src={ChevronDown} width={16} mini slot="icon" />
|
||||||
{node.comment_view.counts.child_count} more
|
{node.comment_view.counts.child_count} more
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface CommentNodeI {
|
|||||||
comment_view: CommentView
|
comment_view: CommentView
|
||||||
children: Array<CommentNodeI>
|
children: Array<CommentNodeI>
|
||||||
depth: number
|
depth: number
|
||||||
|
loading?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCommentParentId(comment?: Comment): number | undefined {
|
function getCommentParentId(comment?: Comment): number | undefined {
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import { PUBLIC_PROXY_URL } from '$env/static/public'
|
|||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
|
||||||
export const DEFAULT_INSTANCE_URL = 'lemmy.world'
|
export const DEFAULT_INSTANCE_URL = 'lemmy.ml'
|
||||||
export let instance = writable(DEFAULT_INSTANCE_URL)
|
export let instance = writable(DEFAULT_INSTANCE_URL)
|
||||||
export let corsSupported = writable(true)
|
export let corsSupported = writable(true)
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{#await data.streamed.comments}
|
{#await data.streamed.comments}
|
||||||
<div class="h-16 mx-auto grid place-items-center">
|
<div class="h-16 mx-auto grid place-items-center">
|
||||||
<Spinner width={36} />
|
<Spinner width={24} />
|
||||||
</div>
|
</div>
|
||||||
{:then comments}
|
{:then comments}
|
||||||
{#if $user}
|
{#if $user}
|
||||||
|
|||||||
Reference in new issue
Block a user