|
@@ -8,19 +8,25 @@
|
|
|
export let size: number = 48;
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
+
|
|
|
const getUserAvatar = async () => {
|
|
|
- try {
|
|
|
- const { data } = await api.userApi.getProfileImage(user.id, {
|
|
|
- responseType: 'blob'
|
|
|
- });
|
|
|
-
|
|
|
- if (data instanceof Blob) {
|
|
|
- return URL.createObjectURL(data);
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- return '/favicon.png';
|
|
|
+ const { data } = await api.userApi.getProfileImage(user.id, {
|
|
|
+ responseType: 'blob'
|
|
|
+ });
|
|
|
+
|
|
|
+ if (data instanceof Blob) {
|
|
|
+ return URL.createObjectURL(data);
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ 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>
|
|
|
|
|
|
{#await getUserAvatar()}
|
|
@@ -41,4 +47,17 @@
|
|
|
title={user.email}
|
|
|
/>
|
|
|
</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}
|