feat: add profile images

This commit is contained in:
Xyphyn committed 2023-09-13 16:09:53 -07:00
1 parent 74f9a9e8fd
commit 6f80d40c43
4 files changed
+28 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "photon-lemmy", "name": "photon-lemmy",
"version": "1.4.7", "version": "1.5.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
+9
View File
@@ -32,6 +32,7 @@ export interface Profile {
jwt?: string jwt?: string
user?: PersonData user?: PersonData
username?: string username?: string
avatar?: string
favorites?: number[] favorites?: number[]
color?: string color?: string
} }
@@ -89,7 +90,13 @@ profile.subscribe(async (p) => {
...p, ...p,
user: user!.user, user: user!.user,
username: user?.user.local_user_view.person.name, username: user?.user.local_user_view.person.name,
avatar: user?.user.local_user_view.person.avatar,
})) }))
profile.update((pro) => {
console.log(pro)
return pro
})
}) })
export async function setUser(jwt: string, inst: string, username: string) { export async function setUser(jwt: string, inst: string, username: string) {
@@ -120,6 +127,7 @@ export async function setUser(jwt: string, inst: string, username: string) {
instance: inst, instance: inst,
jwt: jwt, jwt: jwt,
username: user.user.local_user_view.person.name, username: user.user.local_user_view.person.name,
avatar: user.user.local_user_view.person.avatar,
} }
profile.set({ profile.set({
@@ -212,6 +220,7 @@ export async function setUserID(id: number) {
const user = await userFromJwt(prof.jwt, prof.instance) const user = await userFromJwt(prof.jwt, prof.instance)
instance.set(prof.instance) instance.set(prof.instance)
prof.user = user?.user prof.user = user?.user
prof.avatar = user?.user.local_user_view.person.avatar
site.set(user?.site) site.set(user?.site)
} }
@@ -32,10 +32,7 @@
switching = false switching = false
}} }}
class="w-full hover:bg-slate-200 {expanded ? '' : '!p-1.5'} {$profile?.id == class="w-full hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
prof.id
? 'font-bold'
: ''}"
> >
<ProfileAvatar <ProfileAvatar
profile={prof} profile={prof}
@@ -43,7 +40,10 @@
selected={$profile?.id == prof.id} selected={$profile?.id == prof.id}
slot="prefix" slot="prefix"
/> />
<span class:hidden={!expanded} class="flex flex-col gap-0"> <span
class:hidden={!expanded}
class="flex flex-col gap-0 {$profile?.id == prof.id ? 'font-bold' : ''}"
>
{prof.username ?? prof.user?.local_user_view.person.name} {prof.username ?? prof.user?.local_user_view.person.name}
<span class="text-slate-500 dark:text-zinc-400 font-normal text-xs"> <span class="text-slate-500 dark:text-zinc-400 font-normal text-xs">
{prof.instance} {prof.instance}
+13
View File
@@ -9,6 +9,17 @@
</script> </script>
{#if profile} {#if profile}
<div style="width: {size}px; height: {size}px;">
{#if profile.avatar && !profile.color}
<img
src="{profile.avatar}?thumbnail=32&format=webp"
alt={profile.username}
width={size}
height={size}
class="flex-shrink-0 rounded-full ring-slate-800/50 dark:ring-zinc-200/50"
class:ring-2={selected}
/>
{:else}
<Icon <Icon
src={UserCircle} src={UserCircle}
mini={selected} mini={selected}
@@ -19,4 +30,6 @@
? `color: ${profile.color}` ? `color: ${profile.color}`
: `filter: hue-rotate(${index * 50}deg)`} : `filter: hue-rotate(${index * 50}deg)`}
/> />
{/if}
</div>
{/if} {/if}