@@ -61,6 +61,7 @@ class SubmissionsComponent extends React.Component {
61
61
this . checkIsReviewPhaseComplete = this . checkIsReviewPhaseComplete . bind (
62
62
this
63
63
)
64
+ this . downloadSubmission = this . downloadSubmission . bind ( this )
64
65
}
65
66
66
67
componentDidMount ( ) {
@@ -228,6 +229,37 @@ class SubmissionsComponent extends React.Component {
228
229
} )
229
230
}
230
231
232
+ async downloadSubmission ( submission ) {
233
+ // download submission
234
+ const reactLib = getTopcoderReactLib ( )
235
+ const { getService } = reactLib . services . submissions
236
+ const submissionsService = getService ( this . props . token )
237
+ submissionsService . downloadSubmission ( submission . id )
238
+ . then ( ( blob ) => {
239
+ isValidDownloadFile ( blob ) . then ( ( isValidFile ) => {
240
+ if ( isValidFile . success ) {
241
+ // eslint-disable-next-line no-undef
242
+ const url = window . URL . createObjectURL ( new Blob ( [ blob ] ) )
243
+ const link = document . createElement ( 'a' )
244
+ link . href = url
245
+ let fileName = submission . legacySubmissionId
246
+ if ( ! fileName ) {
247
+ fileName = submission . id
248
+ }
249
+ fileName = fileName + '.zip'
250
+ link . setAttribute ( 'download' , `${ fileName } ` )
251
+ document . body . appendChild ( link )
252
+ link . click ( )
253
+ link . parentNode . removeChild ( link )
254
+ } else {
255
+ this . setState ( {
256
+ alertMessage : isValidFile . message || 'Can not download this submission.'
257
+ } )
258
+ }
259
+ } )
260
+ } )
261
+ }
262
+
231
263
render ( ) {
232
264
const { challenge, token, loggedInUserResource } = this . props
233
265
const { checkpoints, track, type, tags } = challenge
@@ -555,36 +587,7 @@ class SubmissionsComponent extends React.Component {
555
587
< div className = { styles [ 'button-wrapper' ] } >
556
588
< button
557
589
className = { styles [ 'download-submission-button' ] }
558
- onClick = { ( ) => {
559
- // download submission
560
- const reactLib = getTopcoderReactLib ( )
561
- const { getService } = reactLib . services . submissions
562
- const submissionsService = getService ( token )
563
- submissionsService . downloadSubmission ( s . id )
564
- . then ( ( blob ) => {
565
- isValidDownloadFile ( blob ) . then ( ( isValidFile ) => {
566
- if ( isValidFile . success ) {
567
- // eslint-disable-next-line no-undef
568
- const url = window . URL . createObjectURL ( new Blob ( [ blob ] ) )
569
- const link = document . createElement ( 'a' )
570
- link . href = url
571
- let fileName = s . legacySubmissionId
572
- if ( ! fileName ) {
573
- fileName = s . id
574
- }
575
- fileName = fileName + '.zip'
576
- link . setAttribute ( 'download' , `${ fileName } ` )
577
- document . body . appendChild ( link )
578
- link . click ( )
579
- link . parentNode . removeChild ( link )
580
- } else {
581
- this . setState ( {
582
- alertMessage : isValidFile . message || 'Can not download this submission.'
583
- } )
584
- }
585
- } )
586
- } )
587
- } }
590
+ onClick = { ( ) => this . downloadSubmission ( s ) }
588
591
>
589
592
< ReactSVG path = { assets ( `${ Download } ` ) } />
590
593
</ button >
0 commit comments