Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show loading spinner while image loads #2484

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/portal/src/components/media/MediaImageViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
class="h-100 w-100"
v-on="fullImageRendered ? {} : { keydown: handleKeyboardToggleKeydown }"
>
<b-container
v-if="imageLoading"
class="h-100 d-flex align-items-center justify-content-center"
data-qa="loading spinner container"
>
<LoadingSpinner
class="text-white"
size="lg"
/>
</b-container>
<MediaImageViewerKeyboardToggle
id="media-image-viewer-keyboard-toggle"
/>
Expand Down Expand Up @@ -34,6 +44,7 @@
import EuropeanaMediaAnnotation from '@/utils/europeana/media/Annotation.js';
import EuropeanaMediaService from '@/utils/europeana/media/Service.js';

import LoadingSpinner from '../generic/LoadingSpinner.vue';
import MediaImageViewerKeyboardToggle from './MediaImageViewerKeyboardToggle.vue';

export class MediaImageViewerError extends Error {
Expand All @@ -47,6 +58,7 @@
name: 'MediaImageViewer',

components: {
LoadingSpinner,
MediaImageViewerKeyboardToggle
},

Expand Down Expand Up @@ -101,6 +113,7 @@
data() {
return {
fullImageRendered: false,
imageLoading: null,
info: null,
olExtent: null,
olMap: null,
Expand Down Expand Up @@ -321,8 +334,12 @@

const source = new IIIFSource(sourceOptions);
source.on('error', (olError) => this.handleOlError(olError, 'OpenLayers IIIF Source error'));
source.on('imageloadstart', () => this.imageLoading = true);
source.on('imageloaderror', (olError) => this.handleOlError(olError, 'OpenLayers IIIF Source imageloaderror'));
source.on('imageloadend', () => this.imageLoading = false);
source.on('tileloadstart', () => this.imageLoading = true);
source.on('tileloaderror', (olError) => this.handleOlError(olError, 'OpenLayers IIIF Source tileloaderror'));
source.on('tileloadend', () => this.imageLoading = false);
const layer = new TileLayer({ source });
layer.on('error', (olError) => this.handleOlError(olError, 'OpenLayers Tile Layer error'));

Expand All @@ -339,7 +356,9 @@
imageExtent: extent
});
source.on('error', (olError) => this.handleOlError(olError, 'OpenLayers Static Source error'));
source.on('imageloadstart', () => this.imageLoading = true);
source.on('imageloaderror', (olError) => this.handleOlError(olError, 'OpenLayers Static Source imageloaderror'));
source.on('imageloadend', () => this.imageLoading = false);
const layer = new ImageLayer({ source });
layer.on('error', (olError) => this.handleOlError(olError, 'OpenLayers Image Layer error'));

Expand Down
Loading