Skip to content

Commit ec1a7f1

Browse files
simula-rgithub-actions
andauthored
fix: vue nodes image preview widget, better multi image gallery support (#7178)
## Summary Fix image preview to better handle multiple images, switching between them, and showing the skeleton correctly. ## Changes - **What**: ImagePreview.vue ## Screenshots (if applicable) Old (broken) https://github.com/user-attachments/assets/e4997569-bdf5-4015-a83c-bbaabeac96d6 New (fixed) https://github.com/user-attachments/assets/19dda841-c909-4fcb-b4d4-99aa1372843b ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7178-fix-vue-nodes-image-preview-widget-better-multi-image-gallery-support-2c06d73d365081a2afa9e398200e8379) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <[email protected]>
1 parent 5e606f2 commit ec1a7f1

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed
-112 Bytes
Loading

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div
33
v-if="imageUrls.length > 0"
4-
class="image-preview group relative flex size-full min-h-16 min-w-16 flex-col px-2 justify-center"
4+
class="image-preview outline-none group relative flex size-full min-h-16 min-w-16 flex-col px-2 justify-center"
55
tabindex="0"
66
role="region"
77
:aria-label="$t('g.imagePreview')"
@@ -11,29 +11,30 @@
1111
>
1212
<!-- Image Wrapper -->
1313
<div
14-
class="h-full w-full overflow-hidden rounded-[5px] bg-node-component-surface"
14+
class="h-full w-full overflow-hidden rounded-[5px] bg-node-component-surface relative"
1515
>
1616
<!-- Error State -->
1717
<div
1818
v-if="imageError"
19-
class="flex size-full flex-col items-center justify-center bg-smoke-800/50 text-center text-white py-8"
19+
class="flex size-full flex-col items-center justify-center bg-muted-background text-center text-base-foreground py-8"
2020
>
21-
<i class="mb-2 icon-[lucide--image-off] h-12 w-12 text-smoke-400" />
22-
<p class="text-sm text-smoke-300">{{ $t('g.imageFailedToLoad') }}</p>
23-
<p class="mt-1 text-xs text-smoke-400">
21+
<i
22+
class="mb-2 icon-[lucide--image-off] h-12 w-12 text-base-foreground"
23+
/>
24+
<p class="text-sm text-base-foreground">
25+
{{ $t('g.imageFailedToLoad') }}
26+
</p>
27+
<p class="mt-1 text-xs text-base-foreground">
2428
{{ getImageFilename(currentImageUrl) }}
2529
</p>
2630
</div>
27-
2831
<!-- Loading State -->
2932
<Skeleton
3033
v-if="isLoading && !imageError"
31-
class="absolute inset-0 size-full"
3234
border-radius="5px"
33-
width="16rem"
34-
height="16rem"
35+
width="100%"
36+
height="100%"
3537
/>
36-
3738
<!-- Main Image -->
3839
<img
3940
v-if="!imageError"
@@ -83,39 +84,35 @@
8384
<i class="icon-[lucide--x] h-4 w-4" />
8485
</button>
8586
</div>
86-
87-
<!-- Multiple Images Navigation -->
88-
<div
89-
v-if="hasMultipleImages"
90-
class="absolute right-2 bottom-2 left-2 flex justify-center gap-1"
91-
>
92-
<button
93-
v-for="(_, index) in imageUrls"
94-
:key="index"
95-
:class="getNavigationDotClass(index)"
96-
:aria-label="
97-
$t('g.viewImageOfTotal', {
98-
index: index + 1,
99-
total: imageUrls.length
100-
})
101-
"
102-
@click="setCurrentIndex(index)"
103-
/>
104-
</div>
10587
</div>
10688

10789
<!-- Image Dimensions -->
108-
<div class="mt-2 text-center text-xs text-white">
90+
<div class="pt-2 text-center text-xs text-base-foreground">
10991
<span v-if="imageError" class="text-red-400">
11092
{{ $t('g.errorLoadingImage') }}
11193
</span>
112-
<span v-else-if="isLoading" class="text-smoke-400">
94+
<span v-else-if="isLoading" class="text-base-foreground">
11395
{{ $t('g.loading') }}...
11496
</span>
11597
<span v-else>
11698
{{ actualDimensions || $t('g.calculatingDimensions') }}
11799
</span>
118100
</div>
101+
<!-- Multiple Images Navigation -->
102+
<div v-if="hasMultipleImages" class="flex justify-center gap-1 pt-4">
103+
<button
104+
v-for="(_, index) in imageUrls"
105+
:key="index"
106+
:class="getNavigationDotClass(index)"
107+
:aria-label="
108+
$t('g.viewImageOfTotal', {
109+
index: index + 1,
110+
total: imageUrls.length
111+
})
112+
"
113+
@click="setCurrentIndex(index)"
114+
/>
115+
</div>
119116
</div>
120117
</template>
121118

@@ -230,6 +227,7 @@ const handleRemove = () => {
230227
}
231228
232229
const setCurrentIndex = (index: number) => {
230+
if (currentIndex.value === index) return
233231
if (index >= 0 && index < props.imageUrls.length) {
234232
currentIndex.value = index
235233
actualDimensions.value = null
@@ -248,8 +246,10 @@ const handleMouseLeave = () => {
248246
249247
const getNavigationDotClass = (index: number) => {
250248
return [
251-
'w-2 h-2 rounded-full transition-all duration-200 border-0 cursor-pointer',
252-
index === currentIndex.value ? 'bg-white' : 'bg-white/50 hover:bg-white/80'
249+
'w-2 h-2 rounded-full transition-all duration-200 border-0 cursor-pointer p-0',
250+
index === currentIndex.value
251+
? 'bg-base-foreground'
252+
: 'bg-base-foreground/50 hover:bg-base-foreground/80'
253253
]
254254
}
255255

tests-ui/tests/renderer/extensions/vueNodes/components/ImagePreview.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,16 @@ describe('ImagePreview', () => {
225225
const navigationDots = wrapper.findAll('.w-2.h-2.rounded-full')
226226

227227
// First dot should be active (has bg-white class)
228-
expect(navigationDots[0].classes()).toContain('bg-white')
229-
expect(navigationDots[1].classes()).toContain('bg-white/50')
228+
expect(navigationDots[0].classes()).toContain('bg-base-foreground')
229+
expect(navigationDots[1].classes()).toContain('bg-base-foreground/50')
230230

231231
// Switch to second image
232232
await navigationDots[1].trigger('click')
233233
await nextTick()
234234

235235
// Second dot should now be active
236-
expect(navigationDots[0].classes()).toContain('bg-white/50')
237-
expect(navigationDots[1].classes()).toContain('bg-white')
236+
expect(navigationDots[0].classes()).toContain('bg-base-foreground/50')
237+
expect(navigationDots[1].classes()).toContain('bg-base-foreground')
238238
})
239239

240240
it('loads image without errors', async () => {

0 commit comments

Comments
 (0)