@@ -48,23 +48,27 @@ loadStylesheet("https://maxst.icons8.com/vue-static/landings/line-awesome/line-a
4848 downloads : Object
4949 } ,
5050 setup ( props , ctx ) {
51- console . log ( props ) ;
52-
5351 function close ( ) {
5452 ctx . emit ( 'close' )
5553 }
5654
5755 function download ( element ) {
58- ctx . emit ( 'download' , element )
56+ if ( element . isLoading || element . errored ) return ;
57+
58+ element . isLoading = true ;
59+ ctx . emit ( 'download' , element , ( ) => { element . isLoading = false } , ( ) => { element . errored = true } )
5960 }
6061
6162 return { close, download }
6263 } ,
6364 template : /*html*/ `
6465 <div class="slcwd-exports" ref="ref">
65- <button @click="close">x </button>
66+ <button class="slcwd-exports-close" @click="close"><i class="las la-times"></i> </button>
6667 <div v-for="el of downloads">
6768 <button class="slcwd-button" @click="() => download(el)">
69+ <i v-if="el.errored" class="las la-exclamation-circle slcwd-export-error"></i>
70+ <i v-else-if="el.isLoading" class="las la-circle-notch slcwd-spinner"></i>
71+ <i v-else class="las la-file-download"></i>
6872 {{ el.name }}
6973 </button>
7074 </div>
@@ -292,8 +296,8 @@ loadStylesheet("https://maxst.icons8.com/vue-static/landings/line-awesome/line-a
292296 ctx . emit ( 'select' , ret )
293297 }
294298
295- function download ( element ) {
296- ctx . emit ( 'download' , element ) ;
299+ function download ( element , callback , errcallback ) {
300+ ctx . emit ( 'download' , element , callback , errcallback ) ;
297301 }
298302
299303 function closeExportPopup ( ) {
@@ -345,7 +349,7 @@ loadStylesheet("https://maxst.icons8.com/vue-static/landings/line-awesome/line-a
345349 </button>
346350 <button
347351 v-if="downloads.length == 1"
348- @click="() => download(downloads[0])"
352+ @click="() => download(downloads[0], () => {}, () => {} )"
349353 class="slcwd-button"
350354 >
351355 <i class="las la-file-download"></i> <span class="label">{{ downloads[0].name }}</span>
@@ -357,13 +361,13 @@ loadStylesheet("https://maxst.icons8.com/vue-static/landings/line-awesome/line-a
357361 >
358362 <i class="las la-file-download"></i> <span class="label">Download</span>
359363 </button>
360- <ExportPopup
361- v-if="showExportPopup"
362- :downloads=downloads
363- @close="closeExportPopup"
364- @download="download"
365- />
366364 </div>
365+ <ExportPopup
366+ v-show="showExportPopup"
367+ :downloads=downloads
368+ @close="closeExportPopup"
369+ @download="download"
370+ />
367371 `
368372 }
369373
@@ -786,26 +790,31 @@ loadStylesheet("https://maxst.icons8.com/vue-static/landings/line-awesome/line-a
786790 }
787791 )
788792
789- async function download ( element ) {
790- let dataLoc = element . href ;
791- let filename = null ; // If null, will get it from URL
792- if ( dataLoc . startsWith ( "mscz/export:" ) ) {
793- if ( ! WebMscoreSupported . includes ( props . type ) ) { // We have no mscz source file
794- console . error ( "Could not save file, score is not loaded from websmcore" , element ) ;
795- return ;
796- }
797- if ( loader . value == null ) {
798- console . error ( "Loader not available." ) ;
799- return ;
793+ async function download ( element , callback , errcallback ) {
794+ try {
795+ let dataLoc = element . href ;
796+ let filename = null ;
797+ if ( dataLoc . startsWith ( "mscz/export:" ) ) {
798+ if ( ! WebMscoreSupported . includes ( props . type ) ) // We have no mscz source file
799+ throw "Could not save file, score is not loaded from websmcore" ;
800+ if ( loader . value == null )
801+ throw "Loader not available." ;
802+
803+ const exportFormat = dataLoc . split ( ":" ) [ 1 ] ;
804+ const data = await loader . value . exportAs ( exportFormat ) ;
805+ filename = `${ scoreMeta . value . title } .${ exportFormat } ` ;
806+ dataLoc = new Blob ( [ data ] ) ;
807+ } else {
808+ filename = element . href . substr ( element . href . lastIndexOf ( "/" ) + 1 ) ;
800809 }
810+
811+ saveAs ( dataLoc , filename ) ;
812+ callback ( ) ;
801813
802- const exportFormat = dataLoc . split ( ":" ) [ 1 ] ;
803- const data = await loader . value . exportAs ( exportFormat ) ;
804- filename = `${ scoreMeta . value . title } .${ exportFormat } ` ;
805- dataLoc = new Blob ( [ data ] ) ;
814+ } catch ( error ) {
815+ console . error ( `While exporting for "${ element . name } " : ${ error } ` ) ;
816+ errcallback ( ) ;
806817 }
807-
808- saveAs ( dataLoc , filename ) ;
809818 }
810819
811820
0 commit comments