Skip to content

Commit 3a963fe

Browse files
committed
feat(frontend): show already-loaded low-res gallery image while full-res image is loading
1 parent 569d60c commit 3a963fe

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

apps/frontend/src/pages/[type]/[id]/gallery.vue

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,20 @@
137137
<div class="content">
138138
<img
139139
class="image"
140-
:class="{ 'zoomed-in': zoomedIn }"
140+
:class="{ 'zoomed-in': zoomedIn, 'hidden': expandedGalleryImageLoading }"
141141
:src="
142-
expandedGalleryItem.raw_url
143-
? expandedGalleryItem.raw_url
144-
: 'https://cdn.modrinth.com/placeholder-banner.svg'
142+
expandedGalleryItem.raw_url || 'https://cdn.modrinth.com/placeholder-banner.svg'
145143
"
146-
:alt="expandedGalleryItem.title ? expandedGalleryItem.title : 'gallery-image'"
144+
:alt="expandedGalleryItem.title || 'gallery-image'"
145+
@load="expandedGalleryImageLoading = false"
147146
@click.stop
148147
/>
148+
<img
149+
v-if="expandedGalleryImageLoading"
150+
class="image loading-image"
151+
:src="expandedGalleryItem.url || 'https://cdn.modrinth.com/placeholder-banner.svg'"
152+
:alt="expandedGalleryItem.title || 'gallery-image'"
153+
/>
149154

150155
<div class="floating" @click.stop>
151156
<div class="text">
@@ -165,9 +170,7 @@
165170
class="open circle-button"
166171
target="_blank"
167172
:href="
168-
expandedGalleryItem.raw_url
169-
? expandedGalleryItem.raw_url
170-
: 'https://cdn.modrinth.com/placeholder-banner.svg'
173+
expandedGalleryItem.raw_url || 'https://cdn.modrinth.com/placeholder-banner.svg'
171174
"
172175
>
173176
<ExternalIcon aria-hidden="true" />
@@ -220,8 +223,8 @@
220223
<div v-for="(item, index) in project.gallery" :key="index" class="card gallery-item">
221224
<a class="gallery-thumbnail" @click="expandImage(item, index)">
222225
<img
223-
:src="item.url ? item.url : 'https://cdn.modrinth.com/placeholder-banner.svg'"
224-
:alt="item.title ? item.title : 'gallery-image'"
226+
:src="item.url || 'https://cdn.modrinth.com/placeholder-banner.svg'"
227+
:alt="item.title || 'gallery-image'"
225228
/>
226229
</a>
227230
<div class="gallery-body">
@@ -339,6 +342,8 @@ export default defineNuxtComponent({
339342
return {
340343
expandedGalleryItem: null,
341344
expandedGalleryIndex: 0,
345+
expandedGalleryImageLoading: false,
346+
expandedGalleryIndices: [],
342347
zoomedIn: false,
343348
344349
deleteIndex: -1,
@@ -381,18 +386,30 @@ export default defineNuxtComponent({
381386
this.expandedGalleryIndex = 0;
382387
}
383388
this.expandedGalleryItem = this.project.gallery[this.expandedGalleryIndex];
389+
if (!this.expandedGalleryIndices.includes(this.expandedGalleryIndex)) {
390+
this.expandedGalleryImageLoading = true;
391+
this.expandedGalleryIndices.push(this.expandedGalleryIndex)
392+
}
384393
},
385394
previousImage() {
386395
this.expandedGalleryIndex--;
387396
if (this.expandedGalleryIndex < 0) {
388397
this.expandedGalleryIndex = this.project.gallery.length - 1;
389398
}
390399
this.expandedGalleryItem = this.project.gallery[this.expandedGalleryIndex];
400+
if (!this.expandedGalleryIndices.includes(this.expandedGalleryIndex)) {
401+
this.expandedGalleryImageLoading = true;
402+
this.expandedGalleryIndices.push(this.expandedGalleryIndex)
403+
}
391404
},
392405
expandImage(item, index) {
393406
this.expandedGalleryItem = item;
394407
this.expandedGalleryIndex = index;
395408
this.zoomedIn = false;
409+
if (!this.expandedGalleryIndices.includes(index)) {
410+
this.expandedGalleryImageLoading = true;
411+
this.expandedGalleryIndices.push(index)
412+
}
396413
},
397414
resetEdit() {
398415
this.editIndex = -1;
@@ -604,12 +621,21 @@ export default defineNuxtComponent({
604621
max-height: calc(100vh - 2 * var(--spacing-card-lg));
605622
border-radius: var(--size-rounded-card);
606623
624+
&.loading-image {
625+
min-width: calc(60vw - 2 * var(--spacing-card-lg));
626+
min-height: calc(60vh - 2 * var(--spacing-card-lg));
627+
}
628+
607629
&.zoomed-in {
608630
object-fit: cover;
609631
width: auto;
610632
height: calc(100vh - 2 * var(--spacing-card-lg));
611633
max-width: calc(100vw - 2 * var(--spacing-card-lg));
612634
}
635+
636+
&.hidden {
637+
display: none;
638+
}
613639
}
614640
.floating {
615641
position: absolute;

0 commit comments

Comments
 (0)