From 10d717e105e1730637ff55bbae9bd184cfb45c03 Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Sun, 26 Nov 2023 12:30:05 +0700 Subject: [PATCH] fix: fallback nuxt image --- .../ui/src/components/MediaItem/MediaItem.vue | 2 +- .../components/MediaItem/type/ImageMedia.vue | 36 ++++++++++++++----- .../ui/src/components/NeoAvatar/NeoAvatar.vue | 16 +++------ 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/libs/ui/src/components/MediaItem/MediaItem.vue b/libs/ui/src/components/MediaItem/MediaItem.vue index fa15360064..23f7b40097 100644 --- a/libs/ui/src/components/MediaItem/MediaItem.vue +++ b/libs/ui/src/components/MediaItem/MediaItem.vue @@ -96,7 +96,7 @@ const props = withDefaults( original: false, isLewd: false, isDetail: false, - placeholder: '', + placeholder: './Koda.svg', disableOperation: undefined, audioPlayerCover: '', imageComponent: 'img', diff --git a/libs/ui/src/components/MediaItem/type/ImageMedia.vue b/libs/ui/src/components/MediaItem/type/ImageMedia.vue index b118ebec23..145b219c6f 100644 --- a/libs/ui/src/components/MediaItem/type/ImageMedia.vue +++ b/libs/ui/src/components/MediaItem/type/ImageMedia.vue @@ -5,14 +5,32 @@ 'is-square image': !original, 'is-detail': isDetail, }"> + + @error.once="() => onError('error-1')" /> + + + + + @@ -34,16 +52,18 @@ const props = withDefaults( }>(), { sizes: '450px md:350px lg:270px', + imageComponent: 'img', + src: '', + alt: '', }, ) -const onError = (e: Event) => { - const target = e.target as HTMLImageElement - if (target) { - consola.log('[KODADOT::IMAGE] unable to load', props.src, e) - target.removeAttribute('srcset') - target.src = props.placeholder - } +type Status = 'ok' | 'error-1' | 'error-2' +const status = ref('ok') + +const onError = async (phase: Status) => { + consola.log('[KODADOT::IMAGE] unable to load:', `${phase}:`, props.src) + status.value = phase } diff --git a/libs/ui/src/components/NeoAvatar/NeoAvatar.vue b/libs/ui/src/components/NeoAvatar/NeoAvatar.vue index 033ac905ab..6a943b3d73 100644 --- a/libs/ui/src/components/NeoAvatar/NeoAvatar.vue +++ b/libs/ui/src/components/NeoAvatar/NeoAvatar.vue @@ -1,6 +1,7 @@