Handle broken images more gracefully (#10879)

Fixes #10853
This commit is contained in:
Rijk van Zanten
2022-01-05 16:38:41 -05:00
committed by GitHub
parent 4585334e16
commit 8cdb6edfca
3 changed files with 38 additions and 4 deletions

View File

@@ -42,7 +42,13 @@
<router-link :to="userProfileLink">
<v-avatar v-tooltip.right="userFullName" tile large :class="{ 'no-avatar': !avatarURL }">
<img v-if="avatarURL" :src="avatarURL" :alt="userFullName" class="avatar-image" />
<img
v-if="avatarURL && !avatarError"
:src="avatarURL"
:alt="userFullName"
class="avatar-image"
@error="avatarError = $event"
/>
<v-icon v-else name="account_circle" outline />
</v-avatar>
</router-link>
@@ -77,6 +83,8 @@ export default defineComponent({
return addTokenToURL(getRootPath() + `assets/${userStore.currentUser.avatar.id}?key=system-medium-cover`);
});
const avatarError = ref(null);
const userProfileLink = computed<string>(() => {
const id = userStore.currentUser?.id;
return `/users/${id}`;
@@ -88,7 +96,17 @@ export default defineComponent({
const userFullName = userStore.fullName;
return { t, userFullName, avatarURL, userProfileLink, signOutActive, signOutLink, notificationsDrawerOpen, unread };
return {
t,
userFullName,
avatarURL,
userProfileLink,
signOutActive,
signOutLink,
notificationsDrawerOpen,
unread,
avatarError,
};
},
});
</script>