Skip to content

Commit 647405d

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

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

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

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

150153
<div class="floating" @click.stop>
151154
<div class="text">
@@ -165,9 +168,7 @@
165168
class="open circle-button"
166169
target="_blank"
167170
:href="
168-
expandedGalleryItem.raw_url
169-
? expandedGalleryItem.raw_url
170-
: 'https://cdn.modrinth.com/placeholder-banner.svg'
171+
expandedGalleryItem.raw_url || 'https://cdn.modrinth.com/placeholder-banner.svg'
171172
"
172173
>
173174
<ExternalIcon aria-hidden="true" />
@@ -220,8 +221,8 @@
220221
<div v-for="(item, index) in project.gallery" :key="index" class="card gallery-item">
221222
<a class="gallery-thumbnail" @click="expandImage(item, index)">
222223
<img
223-
:src="item.url ? item.url : 'https://cdn.modrinth.com/placeholder-banner.svg'"
224-
:alt="item.title ? item.title : 'gallery-image'"
224+
:src="item.url || 'https://cdn.modrinth.com/placeholder-banner.svg'"
225+
:alt="item.title || 'gallery-image'"
225226
/>
226227
</a>
227228
<div class="gallery-body">
@@ -339,6 +340,8 @@ export default defineNuxtComponent({
339340
return {
340341
expandedGalleryItem: null,
341342
expandedGalleryIndex: 0,
343+
expandedGalleryImageLoading: false,
344+
expandedGalleryIndices: [],
342345
zoomedIn: false,
343346
344347
deleteIndex: -1,
@@ -381,18 +384,30 @@ export default defineNuxtComponent({
381384
this.expandedGalleryIndex = 0;
382385
}
383386
this.expandedGalleryItem = this.project.gallery[this.expandedGalleryIndex];
387+
if (!this.expandedGalleryIndices.includes(this.expandedGalleryIndex)) {
388+
this.expandedGalleryImageLoading = true;
389+
this.expandedGalleryIndices.push(this.expandedGalleryIndex);
390+
}
384391
},
385392
previousImage() {
386393
this.expandedGalleryIndex--;
387394
if (this.expandedGalleryIndex < 0) {
388395
this.expandedGalleryIndex = this.project.gallery.length - 1;
389396
}
390397
this.expandedGalleryItem = this.project.gallery[this.expandedGalleryIndex];
398+
if (!this.expandedGalleryIndices.includes(this.expandedGalleryIndex)) {
399+
this.expandedGalleryImageLoading = true;
400+
this.expandedGalleryIndices.push(this.expandedGalleryIndex);
401+
}
391402
},
392403
expandImage(item, index) {
393404
this.expandedGalleryItem = item;
394405
this.expandedGalleryIndex = index;
395406
this.zoomedIn = false;
407+
if (!this.expandedGalleryIndices.includes(index)) {
408+
this.expandedGalleryImageLoading = true;
409+
this.expandedGalleryIndices.push(index);
410+
}
396411
},
397412
resetEdit() {
398413
this.editIndex = -1;
@@ -604,12 +619,21 @@ export default defineNuxtComponent({
604619
max-height: calc(100vh - 2 * var(--spacing-card-lg));
605620
border-radius: var(--size-rounded-card);
606621
622+
&.loading-image {
623+
min-width: calc(60vw - 2 * var(--spacing-card-lg));
624+
min-height: calc(60vh - 2 * var(--spacing-card-lg));
625+
}
626+
607627
&.zoomed-in {
608628
object-fit: cover;
609629
width: auto;
610630
height: calc(100vh - 2 * var(--spacing-card-lg));
611631
max-width: calc(100vw - 2 * var(--spacing-card-lg));
612632
}
633+
634+
&.hidden {
635+
display: none;
636+
}
613637
}
614638
.floating {
615639
position: absolute;

0 commit comments

Comments
 (0)