fix: Make child loading indicator only appear on parent

This commit is contained in:
Xyphyn committed 2023-07-19 16:09:24 -07:00
1 parent 4c3b5fae6a
commit 0fb17f626f
4 files changed
+18 -8

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,7 +34,8 @@
) )
return return
loadingChildren = true try {
parent.loading = true
const newComments = await getClient().getComments({ const newComments = await getClient().getComments({
auth: $authData?.token, auth: $authData?.token,
@@ -51,8 +53,12 @@
parent.children = buildCommentsTree(newComments.comments, true).find( parent.children = buildCommentsTree(newComments.comments, true).find(
(c) => c.comment_view.comment.id == parent.comment_view.comment.id (c) => c.comment_view.comment.id == parent.comment_view.comment.id
)!.children )!.children
} catch (error) {
loadingChildren = false toast({
content: 'Failed to fetch comments',
type: ToastType.error,
})
}
} }
</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
View File
@@ -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)
+1 -1
View File
@@ -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}