feat: add loader to account sidebar
This commit is contained in:
1 parent
f31fb3047b
commit
f77266e41a
4 files changed
+80
-34
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "photon-lemmy",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
|
||||
@@ -67,6 +67,8 @@
|
||||
export let rounded: ButtonRoundness = 'md'
|
||||
export let alignment: ButtonAlignment = 'center'
|
||||
|
||||
export let loaderWidth: number | undefined = undefined
|
||||
|
||||
// const dispatch = createEventDispatcher()
|
||||
export let href: string | undefined = undefined
|
||||
</script>
|
||||
@@ -96,7 +98,15 @@
|
||||
>
|
||||
{#if loading}
|
||||
<Spinner
|
||||
width={size == 'lg' ? 20 : size == 'md' ? 18 : size == 'sm' ? 16 : 16}
|
||||
width={loaderWidth
|
||||
? loaderWidth
|
||||
: size == 'lg'
|
||||
? 20
|
||||
: size == 'md'
|
||||
? 18
|
||||
: size == 'sm'
|
||||
? 16
|
||||
: 16}
|
||||
/>
|
||||
{:else}
|
||||
<slot name="icon" />
|
||||
@@ -128,7 +138,15 @@
|
||||
>
|
||||
{#if loading}
|
||||
<Spinner
|
||||
width={size == 'lg' ? 20 : size == 'md' ? 18 : size == 'sm' ? 16 : 16}
|
||||
width={loaderWidth
|
||||
? loaderWidth
|
||||
: size == 'lg'
|
||||
? 20
|
||||
: size == 'md'
|
||||
? 18
|
||||
: size == 'sm'
|
||||
? 16
|
||||
: 16}
|
||||
/>
|
||||
{:else}
|
||||
<slot name="icon" />
|
||||
|
||||
@@ -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>
|
||||
@@ -19,6 +19,9 @@
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
|
||||
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
|
||||
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
</script>
|
||||
|
||||
<nav
|
||||
@@ -54,37 +57,10 @@
|
||||
</SidebarButton>
|
||||
{#if $profileData.profiles.length >= 1}
|
||||
<hr class="border-slate-300 dark:border-zinc-800 my-1" />
|
||||
{#each $profileData.profiles as prof, index}
|
||||
<Button
|
||||
color="tertiary"
|
||||
alignment="left"
|
||||
on:click={() => {
|
||||
if ($profile?.id == prof.id) setUserID(-1)
|
||||
else setUserID(prof.id)
|
||||
|
||||
goto($page.url, {
|
||||
invalidateAll: true,
|
||||
})
|
||||
}}
|
||||
class="hover:bg-slate-200 {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '!p-1.5'} {$profile?.id == prof.id ? 'font-bold' : ''}"
|
||||
>
|
||||
<ProfileAvatar
|
||||
profile={prof}
|
||||
{index}
|
||||
selected={$profile?.id == prof.id}
|
||||
/>
|
||||
<span
|
||||
class:hidden={!$userSettings.expandSidebar}
|
||||
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>
|
||||
{#each $profileData.profiles as prof, index (prof.id)}
|
||||
<div animate:flip={{ duration: 300, easing: expoOut }} class="w-full">
|
||||
<ProfileButton {index} {prof} expanded={$userSettings.expandSidebar} />
|
||||
</div>
|
||||
{/each}
|
||||
<SidebarButton href="/accounts" expanded={$userSettings.expandSidebar}>
|
||||
<Icon src={UserGroup} mini size="20" />
|
||||
|
||||
Reference in new issue
Block a user