feat: add loader to account sidebar

This commit is contained in:
Xyphyn committed 2023-08-24 20:41:40 -07:00
1 parent f31fb3047b
commit f77266e41a
4 files changed
+80 -34

No files matched your search

@@ -0,0 +1,52 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { page } from '$app/stores'
import { profile, setUserID, type Profile } from '$lib/auth.js'
import Button from '$lib/components/input/Button.svelte'
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
export let expanded: boolean = false
export let prof: Profile
export let index: number
let switching: boolean = false
</script>
<Button
color="tertiary"
alignment="left"
loading={switching}
loaderWidth={20}
on:click={async () => {
switching = true
if ($profile?.id == prof.id) {
await setUserID(-1)
} else {
await setUserID(prof.id)
}
await goto($page.url, {
invalidateAll: true,
})
switching = false
}}
class="w-full hover:bg-slate-200 {expanded ? '' : '!p-1.5'} {$profile?.id ==
prof.id
? 'font-bold'
: ''}"
>
<ProfileAvatar
profile={prof}
{index}
selected={$profile?.id == prof.id}
slot="icon"
/>
<span class:hidden={!expanded} class="flex flex-col gap-0">
{prof.username ?? prof.user?.local_user_view.person.name}
<span class="text-slate-500 dark:text-zinc-400 font-normal text-xs">
{prof.instance}
</span>
</span>
</Button>