mirror of
https://github.com/immich-app/immich.git
synced 2025-02-04 01:09:14 -05:00
Show the first two letter of user first and last name when profile image not existed (#532)
* Added user first name and last name abbreviation to Circle Avatar: * Remove unsued code
This commit is contained in:
parent
658b64df74
commit
68b1655e7f
2 changed files with 30 additions and 11 deletions
|
@ -8,8 +8,8 @@
|
||||||
export let size: number = 48;
|
export let size: number = 48;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
const getUserAvatar = async () => {
|
const getUserAvatar = async () => {
|
||||||
try {
|
|
||||||
const { data } = await api.userApi.getProfileImage(user.id, {
|
const { data } = await api.userApi.getProfileImage(user.id, {
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
});
|
});
|
||||||
|
@ -17,9 +17,15 @@
|
||||||
if (data instanceof Blob) {
|
if (data instanceof Blob) {
|
||||||
return URL.createObjectURL(data);
|
return URL.createObjectURL(data);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
};
|
||||||
return '/favicon.png';
|
|
||||||
}
|
const getFirstLetter = (text?: string) => {
|
||||||
|
return text?.charAt(0).toUpperCase();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getRandomeBackgroundColor = () => {
|
||||||
|
const colors = ['#DE7FB3', '#E64132', '#FFB800', '#4081EF', '#31A452'];
|
||||||
|
return colors[Math.floor(Math.random() * colors.length)];
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -41,4 +47,17 @@
|
||||||
title={user.email}
|
title={user.email}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
{:catch}
|
||||||
|
<button
|
||||||
|
on:click={() => dispatch('click')}
|
||||||
|
style:width={`${size}px`}
|
||||||
|
style:height={`${size}px`}
|
||||||
|
style:background-color={getRandomeBackgroundColor()}
|
||||||
|
alt="profile-img"
|
||||||
|
class="inline rounded-full object-cover shadow-sm text-white font-semibold"
|
||||||
|
>
|
||||||
|
<div title={user.email}>
|
||||||
|
{getFirstLetter(user.firstName)}{getFirstLetter(user.lastName)}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
{/await}
|
{/await}
|
||||||
|
|
|
@ -41,8 +41,8 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<slot />
|
<slot />
|
||||||
<DownloadPanel />
|
|
||||||
|
|
||||||
|
<DownloadPanel />
|
||||||
<UploadPanel />
|
<UploadPanel />
|
||||||
|
|
||||||
{#if shouldShowAnnouncement}
|
{#if shouldShowAnnouncement}
|
||||||
|
|
Loading…
Add table
Reference in a new issue