@@ -11,6 +11,7 @@ import LoadingIndicator from 'components/LoadingIndicator';
11
11
import SubmissionManagement from 'components/SubmissionManagement/SubmissionManagement' ;
12
12
import React from 'react' ;
13
13
import PT from 'prop-types' ;
14
+ import { safeForDownload } from 'utils/tc' ;
14
15
import { connect } from 'react-redux' ;
15
16
import { Modal , PrimaryButton } from 'topcoder-react-ui-kit' ;
16
17
import { config } from 'topcoder-react-utils' ;
@@ -21,8 +22,22 @@ import smpActions from '../../actions/page/submission_management';
21
22
22
23
const { getService } = services . submissions ;
23
24
25
+ const theme = {
26
+ container : style . modalContainer ,
27
+ } ;
28
+
24
29
// The container component
25
30
class SubmissionManagementPageContainer extends React . Component {
31
+ constructor ( props ) {
32
+ super ( props ) ;
33
+
34
+ this . state = {
35
+ needReload : false ,
36
+ initialState : true ,
37
+ submissions : [ ] ,
38
+ } ;
39
+ }
40
+
26
41
componentDidMount ( ) {
27
42
const {
28
43
authTokens,
@@ -43,6 +58,52 @@ class SubmissionManagementPageContainer extends React.Component {
43
58
}
44
59
}
45
60
61
+ componentWillReceiveProps ( nextProps ) {
62
+ const {
63
+ loadMySubmissions, authTokens, challengeId, mySubmissions,
64
+ } = nextProps ;
65
+ const { needReload } = this . state ;
66
+
67
+ if ( needReload === false && mySubmissions ) {
68
+ if ( mySubmissions . find ( item => safeForDownload ( item . url ) !== true ) ) {
69
+ this . setState ( { needReload : true } ) ;
70
+ setTimeout ( ( ) => {
71
+ loadMySubmissions ( authTokens , challengeId ) ;
72
+ this . setState ( { needReload : false } ) ;
73
+ } , 2000 ) ;
74
+ }
75
+ }
76
+ }
77
+
78
+ componentDidUpdate ( prevProps ) {
79
+ const {
80
+ deletionSucceed,
81
+ toBeDeletedId,
82
+ mySubmissions,
83
+ } = this . props ;
84
+ const { initialState } = this . state ;
85
+
86
+ if ( initialState && mySubmissions ) {
87
+ // eslint-disable-next-line react/no-did-update-set-state
88
+ this . setState ( {
89
+ submissions : [ ...mySubmissions ] ,
90
+ initialState : false ,
91
+ } ) ;
92
+ return ;
93
+ }
94
+ const { submissions } = this . state ;
95
+
96
+ if ( deletionSucceed !== prevProps . deletionSucceed ) {
97
+ _ . remove ( submissions , submission => (
98
+ submission . id === toBeDeletedId
99
+ ) ) ;
100
+ // eslint-disable-next-line react/no-did-update-set-state
101
+ this . setState ( {
102
+ submissions,
103
+ } ) ;
104
+ }
105
+ }
106
+
46
107
render ( ) {
47
108
const {
48
109
authTokens,
@@ -53,7 +114,6 @@ class SubmissionManagementPageContainer extends React.Component {
53
114
loadingSubmissionsForChallengeId,
54
115
submissionPhaseStartDate,
55
116
isLoadingChallenge,
56
- mySubmissions,
57
117
onCancelSubmissionDelete,
58
118
onShowDetails,
59
119
onSubmissionDelete,
@@ -62,6 +122,9 @@ class SubmissionManagementPageContainer extends React.Component {
62
122
showModal,
63
123
toBeDeletedId,
64
124
} = this . props ;
125
+
126
+ const { submissions } = this . state ;
127
+
65
128
if ( ! challenge . isRegistered ) return < AccessDenied redirectLink = { `${ challengesUrl } /${ challenge . id } ` } cause = { ACCESS_DENIED_REASON . HAVE_NOT_SUBMITTED_TO_THE_CHALLENGE } /> ;
66
129
67
130
const isEmpty = _ . isEmpty ( challenge ) ;
@@ -96,7 +159,7 @@ class SubmissionManagementPageContainer extends React.Component {
96
159
challenge = { challenge }
97
160
challengesUrl = { challengesUrl }
98
161
loadingSubmissions = { Boolean ( loadingSubmissionsForChallengeId ) }
99
- submissions = { mySubmissions }
162
+ submissions = { submissions }
100
163
showDetails = { showDetails }
101
164
submissionPhaseStartDate = { submissionPhaseStartDate }
102
165
{ ...smConfig }
@@ -108,6 +171,7 @@ class SubmissionManagementPageContainer extends React.Component {
108
171
{ showModal && (
109
172
< Modal
110
173
onCancel = { deleting ? _ . noop : onCancelSubmissionDelete }
174
+ theme = { theme }
111
175
>
112
176
< div styleName = "modal-content" >
113
177
< p styleName = "are-you-sure" >
@@ -123,6 +187,8 @@ class SubmissionManagementPageContainer extends React.Component {
123
187
This will permanently remove all
124
188
files from our servers and can’t be undone.
125
189
You’ll have to upload all the files again in order to restore it.
190
+ Note that deleting the file may take a few minutes to propagate
191
+ through the Topcoder platform.
126
192
</ p >
127
193
< div
128
194
/* NOTE: Current implementation of the loading indicator is
@@ -179,6 +245,7 @@ SubmissionManagementPageContainer.defaultProps = {
179
245
showModal : false ,
180
246
toBeDeletedId : '' ,
181
247
challenge : null ,
248
+ deletionSucceed : false ,
182
249
} ;
183
250
184
251
SubmissionManagementPageContainer . propTypes = {
@@ -199,6 +266,7 @@ SubmissionManagementPageContainer.propTypes = {
199
266
showModal : PT . bool ,
200
267
onCancelSubmissionDelete : PT . func . isRequired ,
201
268
toBeDeletedId : PT . string ,
269
+ deletionSucceed : PT . bool ,
202
270
onSubmissionDeleteConfirmed : PT . func . isRequired ,
203
271
submissionPhaseStartDate : PT . string . isRequired ,
204
272
} ;
@@ -232,6 +300,7 @@ function mapStateToProps(state, props) {
232
300
233
301
showModal : state . page . submissionManagement . showModal ,
234
302
toBeDeletedId : state . page . submissionManagement . toBeDeletedId ,
303
+ deletionSucceed : state . page . submissionManagement . deletionSucceed ,
235
304
236
305
authTokens : state . auth ,
237
306
registrants : state . challenge . details . registrants ,
0 commit comments