Add loading spinner to document and image forms
This commit is contained in:
parent
d550b7057d
commit
10dc8361ff
|
|
@ -7,6 +7,12 @@
|
||||||
v-if="!value.url"
|
v-if="!value.url"
|
||||||
ref="uploadcare-panel"
|
ref="uploadcare-panel"
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
class="document-form__spinner"
|
||||||
|
v-if="loading"
|
||||||
|
>
|
||||||
|
<loading-icon class="document-form__loading-icon" />
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="document-form__uploaded"
|
class="document-form__uploaded"
|
||||||
v-if="value.url"
|
v-if="value.url"
|
||||||
|
|
@ -23,6 +29,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {uploadcare} from '@/helpers/uploadcare';
|
import {uploadcare} from '@/helpers/uploadcare';
|
||||||
|
import LoadingIcon from '@/components/icons/LoadingIcon';
|
||||||
|
|
||||||
const DocumentIcon = () => import(/* webpackChunkName: "icons" */'@/components/icons/DocumentIcon');
|
const DocumentIcon = () => import(/* webpackChunkName: "icons" */'@/components/icons/DocumentIcon');
|
||||||
|
|
||||||
|
|
@ -30,7 +37,14 @@
|
||||||
props: ['value', 'index'],
|
props: ['value', 'index'],
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
DocumentIcon
|
LoadingIcon,
|
||||||
|
DocumentIcon,
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -46,19 +60,23 @@
|
||||||
return parts[parts.length - 1];
|
return parts[parts.length - 1];
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
uploadcare(this, url => {
|
uploadcare(this, url => {
|
||||||
this.$emit('change-url', url, this.index);
|
this.$emit('change-url', url, this.index);
|
||||||
|
this.loading = false;
|
||||||
|
}, () => {
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@import "~styles/variables";
|
@import "~styles/helpers";
|
||||||
|
|
||||||
.document-form {
|
.document-form {
|
||||||
&__uploaded {
|
&__uploaded {
|
||||||
|
|
@ -70,6 +88,19 @@
|
||||||
text-decoration: underline;
|
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 {
|
&__icon {
|
||||||
width: 30px;
|
width: 30px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,20 @@
|
||||||
>Dokument</a> hoch.
|
>Dokument</a> hoch.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="image-form__spinner"
|
||||||
|
v-if="loading"
|
||||||
|
>
|
||||||
|
<loading-icon class="image-form__loading-icon" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="!value.url"
|
v-if="!value.url"
|
||||||
ref="uploadcare-panel"
|
ref="uploadcare-panel"
|
||||||
/>
|
/>
|
||||||
<div v-if="value.url && !hadError">
|
<div v-if="value.url && !hadError">
|
||||||
<img
|
<img
|
||||||
|
alt=""
|
||||||
:src="previewUrl"
|
:src="previewUrl"
|
||||||
@error="error"
|
@error="error"
|
||||||
>
|
>
|
||||||
|
|
@ -25,15 +33,18 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import uploadcare from 'uploadcare-widget';
|
import uploadcare from 'uploadcare-widget';
|
||||||
|
import LoadingIcon from '@/components/icons/LoadingIcon';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['value', 'index'],
|
props: ['value', 'index'],
|
||||||
|
components: {LoadingIcon},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hadError: false,
|
hadError: false,
|
||||||
uploadcarePanel: null,
|
uploadcarePanel: null,
|
||||||
url: '',
|
url: '',
|
||||||
filename: ''
|
filename: '',
|
||||||
|
loading: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -42,7 +53,7 @@
|
||||||
return this.value.url + '-/preview/200x200/';
|
return this.value.url + '-/preview/200x200/';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.mountUploadcare();
|
this.mountUploadcare();
|
||||||
|
|
@ -62,8 +73,10 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
this.uploadcarePanel.done(panelResult => {
|
this.uploadcarePanel.done(panelResult => {
|
||||||
|
this.loading = true;
|
||||||
panelResult.done(fileInfo => {
|
panelResult.done(fileInfo => {
|
||||||
this.hadError = false;
|
this.hadError = false;
|
||||||
|
this.loading = false;
|
||||||
this.url = fileInfo.cdnUrl;
|
this.url = fileInfo.cdnUrl;
|
||||||
this.filename = fileInfo.name;
|
this.filename = fileInfo.name;
|
||||||
this.$emit('change-url', fileInfo.cdnUrl, this.index);
|
this.$emit('change-url', fileInfo.cdnUrl, this.index);
|
||||||
|
|
@ -76,10 +89,10 @@
|
||||||
},
|
},
|
||||||
switchToDocument() {
|
switchToDocument() {
|
||||||
this.$emit('switch-to-document', this.index, {
|
this.$emit('switch-to-document', this.index, {
|
||||||
url: `${this.url}${this.filename}`
|
url: `${this.url}${this.filename}`,
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -93,6 +106,19 @@
|
||||||
line-height: 1.5;
|
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 {
|
&__link {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@include regular-text;
|
@include regular-text;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 100 100"
|
viewBox="0 0 100 100"
|
||||||
|
width="100"
|
||||||
|
height="100"
|
||||||
>
|
>
|
||||||
<path
|
<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"
|
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"
|
||||||
|
|
|
||||||
|
|
@ -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 => {
|
.then(module => {
|
||||||
const uploadcareWidget = module.default;
|
const uploadcareWidget = module.default;
|
||||||
|
|
||||||
|
|
@ -16,6 +16,7 @@ export const uploadcare = (component, callback) => import(/* webpackChunkName: "
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
return uploadcarePanel.done(panelResult => {
|
return uploadcarePanel.done(panelResult => {
|
||||||
|
onStart();
|
||||||
panelResult.done(fileInfo => {
|
panelResult.done(fileInfo => {
|
||||||
let urlWithFilename = fileInfo.cdnUrl + fileInfo.name;
|
let urlWithFilename = fileInfo.cdnUrl + fileInfo.name;
|
||||||
callback(urlWithFilename);
|
callback(urlWithFilename);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue