Skip to content

Commit d50a2fa

Browse files
authored
Fix skeleton loaders for Image/Video Previews (#7094)
This pull request refines the loading and error handling logic for both the `VideoPreview.vue` and `ImagePreview.vue` components. The main improvements include making the loading skeleton more accurate and visually consistent, updating how loading and error states are managed when URLs change, and ensuring that the main media elements are hidden while loading. These changes enhance the user experience by providing clearer feedback during media load operations. **Loading and error state improvements:** * The loading skeleton in both `VideoPreview.vue` and `ImagePreview.vue` now only appears when loading and no error is present, with updated styling and fixed dimensions for better consistency. (`VideoPreview.vue` [[1]](diffhunk://#diff-17b5c19b4628f22e45570b66a85ed1fc16e931dd368fe420584d487e522ab8aaL29-R41) `ImagePreview.vue` [[2]](diffhunk://#diff-0c0b17c5c68464e0284398ad42b823509d414c9cf297f3bc2aa2b00e0f9c2015L29-R48) * The main video and image elements are now hidden (using the `invisible` class) while loading, preventing display glitches before the media is ready. (`VideoPreview.vue` [[1]](diffhunk://#diff-17b5c19b4628f22e45570b66a85ed1fc16e931dd368fe420584d487e522ab8aaL29-R41) `ImagePreview.vue` [[2]](diffhunk://#diff-0c0b17c5c68464e0284398ad42b823509d414c9cf297f3bc2aa2b00e0f9c2015L29-R48) * The loading state (`isLoading`) is now set to `true` whenever new URLs are provided, and reset appropriately when navigating between media items, ensuring accurate feedback to the user. (`VideoPreview.vue` [[1]](diffhunk://#diff-17b5c19b4628f22e45570b66a85ed1fc16e931dd368fe420584d487e522ab8aaL145-R152) `ImagePreview.vue` [[2]](diffhunk://#diff-0c0b17c5c68464e0284398ad42b823509d414c9cf297f3bc2aa2b00e0f9c2015L164-R176) [[3]](diffhunk://#diff-0c0b17c5c68464e0284398ad42b823509d414c9cf297f3bc2aa2b00e0f9c2015L224-R236) **Code consistency and maintainability:** * Both components now import and use the shared `cn` utility for conditional class names, improving code consistency and maintainability. (`VideoPreview.vue` [[1]](diffhunk://#diff-17b5c19b4628f22e45570b66a85ed1fc16e931dd368fe420584d487e522ab8aaR115) `ImagePreview.vue` [[2]](diffhunk://#diff-0c0b17c5c68464e0284398ad42b823509d414c9cf297f3bc2aa2b00e0f9c2015R132) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7094-Fix-skeleton-loaders-for-Image-Video-Previews-2bd6d73d3650817989e1f4d597094016) by [Unito](https://www.unito.io)
1 parent 9c5f8a6 commit d50a2fa

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/renderer/extensions/vueNodes/VideoPreview.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@
2626
</div>
2727

2828
<!-- Loading State -->
29-
<Skeleton v-else-if="isLoading" class="size-full" border-radius="5px" />
29+
<Skeleton
30+
v-if="isLoading && !videoError"
31+
class="absolute inset-0 size-full"
32+
border-radius="5px"
33+
width="16rem"
34+
height="16rem"
35+
/>
3036

3137
<!-- Main Video -->
3238
<video
33-
v-else
39+
v-if="!videoError"
3440
:src="currentVideoUrl"
35-
class="block size-full object-contain"
41+
:class="cn('block size-full object-contain', isLoading && 'invisible')"
3642
controls
3743
loop
3844
playsinline
@@ -106,6 +112,7 @@ import { useI18n } from 'vue-i18n'
106112
107113
import { downloadFile } from '@/base/common/downloadUtil'
108114
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
115+
import { cn } from '@/utils/tailwindUtil'
109116
110117
interface VideoPreviewProps {
111118
/** Array of video URLs to display */
@@ -142,7 +149,7 @@ watch(
142149
// Reset loading and error states when URLs change
143150
actualDimensions.value = null
144151
videoError.value = false
145-
isLoading.value = false
152+
isLoading.value = newUrls.length > 0
146153
},
147154
{ deep: true }
148155
)

src/renderer/extensions/vueNodes/components/ImagePreview.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,26 @@
2626
</div>
2727

2828
<!-- Loading State -->
29-
<Skeleton v-else-if="isLoading" class="size-full" border-radius="5px" />
29+
<Skeleton
30+
v-if="isLoading && !imageError"
31+
class="absolute inset-0 size-full"
32+
border-radius="5px"
33+
width="16rem"
34+
height="16rem"
35+
/>
3036

3137
<!-- Main Image -->
3238
<img
33-
v-else
39+
v-if="!imageError"
3440
ref="currentImageEl"
3541
:src="currentImageUrl"
3642
:alt="imageAltText"
37-
class="block size-full object-contain pointer-events-none"
43+
:class="
44+
cn(
45+
'block size-full object-contain pointer-events-none',
46+
isLoading && 'invisible'
47+
)
48+
"
3849
@load="handleImageLoad"
3950
@error="handleImageError"
4051
/>
@@ -118,6 +129,7 @@ import { downloadFile } from '@/base/common/downloadUtil'
118129
import { app } from '@/scripts/app'
119130
import { useCommandStore } from '@/stores/commandStore'
120131
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
132+
import { cn } from '@/utils/tailwindUtil'
121133
122134
interface ImagePreviewProps {
123135
/** Array of image URLs to display */
@@ -161,7 +173,7 @@ watch(
161173
// Reset loading and error states when URLs change
162174
actualDimensions.value = null
163175
imageError.value = false
164-
isLoading.value = false
176+
isLoading.value = newUrls.length > 0
165177
},
166178
{ deep: true }
167179
)
@@ -221,7 +233,7 @@ const setCurrentIndex = (index: number) => {
221233
if (index >= 0 && index < props.imageUrls.length) {
222234
currentIndex.value = index
223235
actualDimensions.value = null
224-
isLoading.value = false
236+
isLoading.value = true
225237
imageError.value = false
226238
}
227239
}

0 commit comments

Comments
 (0)