Add loading spinner to document and image forms

This commit is contained in:
Ramon Wenger 2022-02-16 15:11:59 +01:00
parent d550b7057d
commit 10dc8361ff
4 changed files with 69 additions and 9 deletions

View File

@ -7,6 +7,12 @@
v-if="!value.url"
ref="uploadcare-panel"
/>
<div
class="document-form__spinner"
v-if="loading"
>
<loading-icon class="document-form__loading-icon" />
</div>
<div
class="document-form__uploaded"
v-if="value.url"
@ -23,6 +29,7 @@
<script>
import {uploadcare} from '@/helpers/uploadcare';
import LoadingIcon from '@/components/icons/LoadingIcon';
const DocumentIcon = () => import(/* webpackChunkName: "icons" */'@/components/icons/DocumentIcon');
@ -30,7 +37,14 @@
props: ['value', 'index'],
components: {
DocumentIcon
LoadingIcon,
DocumentIcon,
},
data() {
return {
loading: false,
};
},
computed: {
@ -46,19 +60,23 @@
return parts[parts.length - 1];
}
return '';
}
},
},
mounted() {
uploadcare(this, url => {
this.$emit('change-url', url, this.index);
this.loading = false;
}, () => {
this.loading = true;
});
},
};
</script>
<style scoped lang="scss">
@import "~styles/variables";
@import "~styles/helpers";
.document-form {
&__uploaded {
@ -70,6 +88,19 @@
text-decoration: underline;
}
&__spinner {
width: 100%;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
}
&__loading-icon {
@include spin;
fill: $color-silver-dark;
}
&__icon {
width: 30px;
height: 30px;

View File

@ -10,12 +10,20 @@
>Dokument</a> hoch.
</div>
<div
class="image-form__spinner"
v-if="loading"
>
<loading-icon class="image-form__loading-icon" />
</div>
<div
v-if="!value.url"
ref="uploadcare-panel"
/>
<div v-if="value.url && !hadError">
<img
alt=""
:src="previewUrl"
@error="error"
>
@ -25,15 +33,18 @@
<script>
import uploadcare from 'uploadcare-widget';
import LoadingIcon from '@/components/icons/LoadingIcon';
export default {
props: ['value', 'index'],
components: {LoadingIcon},
data() {
return {
hadError: false,
uploadcarePanel: null,
url: '',
filename: ''
filename: '',
loading: false,
};
},
computed: {
@ -42,7 +53,7 @@
return this.value.url + '-/preview/200x200/';
}
return null;
}
},
},
mounted() {
this.mountUploadcare();
@ -62,8 +73,10 @@
});
this.uploadcarePanel.done(panelResult => {
this.loading = true;
panelResult.done(fileInfo => {
this.hadError = false;
this.loading = false;
this.url = fileInfo.cdnUrl;
this.filename = fileInfo.name;
this.$emit('change-url', fileInfo.cdnUrl, this.index);
@ -76,10 +89,10 @@
},
switchToDocument() {
this.$emit('switch-to-document', this.index, {
url: `${this.url}${this.filename}`
url: `${this.url}${this.filename}`,
});
}
}
},
},
};
</script>
@ -93,6 +106,19 @@
line-height: 1.5;
}
&__spinner {
width: 100%;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
}
&__loading-icon {
@include spin;
fill: $color-silver-dark;
}
&__link {
text-decoration: underline;
@include regular-text;

View File

@ -2,6 +2,8 @@
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100"
width="100"
height="100"
>
<path
d="M91,47.5A2.5,2.5,0,0,0,88.5,50,38.5,38.5,0,1,1,50,11.5,38.09,38.09,0,0,1,76,21.64H62.13a2.45,2.45,0,0,0,0,4.9H84.31V4.36a2.45,2.45,0,1,0-4.9,0V18A43,43,0,0,0,50,6.5,43.5,43.5,0,1,0,93.5,50,2.5,2.5,0,0,0,91,47.5Z"

View File

@ -1,4 +1,4 @@
export const uploadcare = (component, callback) => import(/* webpackChunkName: "uploadcare" */'uploadcare-widget')
export const uploadcare = (component, callback, onStart = () => {}) => import(/* webpackChunkName: "uploadcare" */'uploadcare-widget')
.then(module => {
const uploadcareWidget = module.default;
@ -16,6 +16,7 @@ export const uploadcare = (component, callback) => import(/* webpackChunkName: "
}, 0);
return uploadcarePanel.done(panelResult => {
onStart();
panelResult.done(fileInfo => {
let urlWithFilename = fileInfo.cdnUrl + fileInfo.name;
callback(urlWithFilename);