8
8
EditOutlined ,
9
9
FileUnknownTwoTone ,
10
10
EyeOutlined ,
11
- EyeInvisibleOutlined
11
+ EyeInvisibleOutlined ,
12
+ RedoOutlined
12
13
} from '@ant-design/icons' ;
13
14
import './App.css' ;
14
15
import AdminChallengeCreate from "./adminChallengeCreate.js" ;
@@ -36,19 +37,20 @@ class AdminChallenges extends React.Component {
36
37
selectedKeys : [ ] ,
37
38
targetKeys : [ ] ,
38
39
allCat : [ ] ,
39
- transferDisabled : false
40
+ transferDisabled : false ,
41
+ refreshLoading : false
40
42
}
41
43
}
42
44
43
- componentDidUpdate ( prevProps ) {
44
- // Handle any page changes
45
- if ( this . state . editChallenge && this . props . location . pathname !== "/Admin/Challenges/Edit" ) {
46
- this . setState ( { editChallenge : false } )
47
- }
48
- else if ( this . state . challengeCreate && this . props . location . pathname !== "/Admin/Challenges/Create" ) {
49
- this . setState ( { challengeCreate : false } )
45
+ componentDidUpdate ( prevProps ) {
46
+ // Handle any page changes
47
+ if ( this . state . editChallenge && this . props . location . pathname !== "/Admin/Challenges/Edit" ) {
48
+ this . setState ( { editChallenge : false } )
49
+ }
50
+ else if ( this . state . challengeCreate && this . props . location . pathname !== "/Admin/Challenges/Create" ) {
51
+ this . setState ( { challengeCreate : false } )
52
+ }
50
53
}
51
- }
52
54
53
55
54
56
componentDidMount = async ( ) => {
@@ -60,38 +62,36 @@ class AdminChallenges extends React.Component {
60
62
message . warn ( "Please select a challenge from the table to edit" )
61
63
await this . props . history . push ( "/Admin/Challenges" )
62
64
}
63
- this . fillTableData ( )
64
- this . handleCategoryData ( )
65
+ this . handleRefresh ( )
65
66
}
66
67
67
68
68
- handleCategoryData ( ) {
69
+ handleCategoryData = async ( ) => {
69
70
this . setState ( { transferDisabled : true } )
70
71
let visibleCat = [ ]
71
72
let allCat = [ ]
72
73
73
- const getInfo = async ( ) => {
74
- fetch ( window . ipAddress + "/v1/challenge/list_categories" , {
75
- method : 'get' ,
76
- headers : { 'Content-Type' : 'application/json' , "Authorization" : localStorage . getItem ( "IRSCTF-token" ) } ,
77
- } ) . then ( ( results ) => {
78
- return results . json ( ) ; //return data in JSON (since its JSON data)
79
- } ) . then ( ( data ) => {
74
+ await Promise . all ( [ fetch ( window . ipAddress + "/v1/challenge/list_categories" , {
75
+ method : 'get' ,
76
+ headers : { 'Content-Type' : 'application/json' , "Authorization" : localStorage . getItem ( "IRSCTF-token" ) } ,
77
+ } ) . then ( ( results ) => {
78
+ return results . json ( ) ; //return data in JSON (since its JSON data)
79
+ } ) . then ( ( data ) => {
80
80
81
- if ( data . success === true ) {
82
- visibleCat = data . categories
83
- }
84
- else {
85
- message . error ( { content : "Oops. Unknown error" } )
86
- }
81
+ if ( data . success === true ) {
82
+ visibleCat = data . categories
83
+ }
84
+ else {
85
+ message . error ( { content : "Oops. Unknown error" } )
86
+ }
87
87
88
88
89
- } ) . catch ( ( error ) => {
90
- console . log ( error )
91
- message . error ( { content : "Oops. There was an issue connecting with the server" } ) ;
92
- } )
89
+ } ) . catch ( ( error ) => {
90
+ console . log ( error )
91
+ message . error ( { content : "Oops. There was an issue connecting with the server" } ) ;
92
+ } )
93
93
94
- await fetch ( window . ipAddress + "/v1/challenge/list_all_categories" , {
94
+ , fetch ( window . ipAddress + "/v1/challenge/list_all_categories" , {
95
95
method : 'get' ,
96
96
headers : { 'Content-Type' : 'application/json' , "Authorization" : localStorage . getItem ( "IRSCTF-token" ) } ,
97
97
} ) . then ( ( results ) => {
@@ -110,22 +110,17 @@ class AdminChallenges extends React.Component {
110
110
console . log ( error )
111
111
message . error ( { content : "Oops. There was an issue connecting with the server" } ) ;
112
112
} )
113
+ ] )
113
114
115
+ let invisible = difference ( allCat , visibleCat )
116
+ /*console.log(invisible)
117
+ console.log(allCat)
118
+ console.log(visibleCat)*/
114
119
120
+ for ( let i = 0 ; i < allCat . length ; i ++ ) {
121
+ allCat [ i ] = { "key" : allCat [ i ] }
115
122
}
116
-
117
- ( async ( ) => {
118
- await getInfo ( )
119
- let invisible = difference ( allCat , visibleCat )
120
- /*console.log(invisible)
121
- console.log(allCat)
122
- console.log(visibleCat)*/
123
-
124
- for ( let i = 0 ; i < allCat . length ; i ++ ) {
125
- allCat [ i ] = { "key" : allCat [ i ] }
126
- }
127
- this . setState ( { targetKeys : invisible , allCat : allCat , transferDisabled : false } )
128
- } ) ( )
123
+ this . setState ( { targetKeys : invisible , allCat : allCat , transferDisabled : false } )
129
124
}
130
125
131
126
handleChange = ( nextTargetKeys , direction , moveKeys ) => {
@@ -172,9 +167,9 @@ class AdminChallenges extends React.Component {
172
167
} )
173
168
}
174
169
175
- fillTableData = ( ) => {
170
+ fillTableData = async ( ) => {
176
171
this . setState ( { loading : true } )
177
- fetch ( window . ipAddress + "/v1/challenge/list_all" , {
172
+ await fetch ( window . ipAddress + "/v1/challenge/list_all" , {
178
173
method : 'get' ,
179
174
headers : { 'Content-Type' : 'application/json' , "Authorization" : localStorage . getItem ( "IRSCTF-token" ) } ,
180
175
} ) . then ( ( results ) => {
@@ -191,6 +186,7 @@ class AdminChallenges extends React.Component {
191
186
}
192
187
}
193
188
this . setState ( { dataSource : data . challenges , loading : false } )
189
+
194
190
}
195
191
else {
196
192
message . error ( { content : "Oops. Unknown error" } )
@@ -217,8 +213,7 @@ class AdminChallenges extends React.Component {
217
213
//console.log(data)
218
214
if ( data . success === true ) {
219
215
message . success ( { content : "Deleted challenge \"" + challengeName + "\" successfully" } )
220
- this . fillTableData ( )
221
- this . handleCategoryData ( )
216
+ this . handleRefresh ( )
222
217
223
218
}
224
219
else {
@@ -249,15 +244,17 @@ class AdminChallenges extends React.Component {
249
244
handleCreateBack ( ) {
250
245
this . props . history . push ( "/Admin/Challenges" )
251
246
this . setState ( { challengeCreate : false } )
252
- this . fillTableData ( )
253
- this . handleCategoryData ( )
247
+ this . handleRefresh ( )
254
248
}
255
249
256
250
handleEditChallBack ( ) {
257
251
this . props . history . push ( "/Admin/Challenges" )
258
252
this . setState ( { editChallenge : false } )
259
- this . fillTableData ( )
260
- this . handleCategoryData ( )
253
+ this . handleRefresh ( )
254
+ }
255
+
256
+ handleRefresh = async ( ) => {
257
+ await Promise . all ( [ this . fillTableData ( ) , this . handleCategoryData ( ) ] )
261
258
}
262
259
263
260
@@ -269,24 +266,26 @@ class AdminChallenges extends React.Component {
269
266
270
267
< Layout style = { { height : "100%" , width : "100%" , backgroundColor : "rgba(0, 0, 0, 0)" } } >
271
268
272
- { this . state . loading && (
273
- < div style = { { position : "absolute" , left : "55%" , transform : "translate(-55%, 0%)" , zIndex : 10 } } >
274
- < Ellipsis color = "#177ddc" size = { 120 } > </ Ellipsis >
275
- </ div >
276
- ) }
277
- { ! this . state . loading && (
278
- < div >
279
-
280
- { ! this . state . challengeCreate && ! this . state . editChallenge && (
281
- < div >
282
269
283
- < Button type = "primary" style = { { marginBottom : "2vh" , maxWidth : "25ch" } } icon = { < FlagOutlined /> } onClick = { ( ) => { this . setState ( { challengeCreate : true } , this . props . history . push ( "/Admin/Challenges/Create" ) ) } } > Create New Challenge</ Button >
284
270
271
+ { ! this . state . challengeCreate && ! this . state . editChallenge && (
272
+ < div >
273
+ < div style = { { display : "flex" , justifyContent : "space-between" , alignItems : "center" } } >
274
+ < Button type = "primary" style = { { marginBottom : "2vh" , maxWidth : "25ch" } } icon = { < FlagOutlined /> } onClick = { ( ) => { this . setState ( { challengeCreate : true } , this . props . history . push ( "/Admin/Challenges/Create" ) ) } } > Create New Challenge</ Button >
275
+ < Button loading = { this . state . loading } type = "primary" shape = "circle" size = "large" style = { { marginBottom : "2vh" , maxWidth : "25ch" } } icon = { < RedoOutlined /> } onClick = { async ( ) => { await this . handleRefresh ( ) ; message . success ( "Challenge list refreshed." ) } } />
276
+ </ div >
277
+ { this . state . loading && (
278
+ < div style = { { display : "flex" , justifyContent : "center" , alignItems : "center" } } >
279
+ < Ellipsis color = "#177ddc" size = { 120 } > </ Ellipsis >
280
+ </ div >
281
+ ) }
282
+ { ! this . state . loading && (
283
+ < div >
285
284
< Table style = { { overflow : "auto" } } dataSource = { this . state . dataSource } locale = { {
286
285
emptyText : (
287
286
< div style = { { display : "flex" , flexDirection : "column" , alignItems : "center" , justifyContent : "center" , marginTop : "10vh" } } >
288
287
< FileUnknownTwoTone style = { { color : "#177ddc" , fontSize : "400%" , zIndex : 1 } } />
289
- < h1 style = { { fontSize : "200%" } } > There are no challenges created .</ h1 >
288
+ < h1 style = { { fontSize : "200%" } } > No Challenges Have Been Created .</ h1 >
290
289
</ div >
291
290
)
292
291
} } >
@@ -329,35 +328,37 @@ class AdminChallenges extends React.Component {
329
328
) }
330
329
/>
331
330
</ Table >
332
- < Divider />
333
- < h1 style = { { fontSize : "150%" } } > Category Management { this . state . transferDisabled && ( < LoadingOutlined style = { { color : "#177ddc" } } /> ) } </ h1 >
334
-
335
- < Transfer
336
- dataSource = { this . state . allCat }
337
- titles = { [ 'Visible Categories' , 'Hidden Categories' ] }
338
- targetKeys = { this . state . targetKeys }
339
- selectedKeys = { this . state . selectedKeys }
340
- onChange = { this . handleChange }
341
- onSelectChange = { this . handleSelectChange }
342
- render = { item => item . key }
343
- pagination
344
- disabled = { this . state . transferDisabled }
345
- />
346
-
347
- < Divider />
348
331
</ div >
349
332
) }
350
- < Switch >
351
- < Route exact path = '/Admin/Challenges/Create' render = { ( props ) => < AdminChallengeCreate { ...props } handleBack = { this . handleBack . bind ( this ) } handleCreateBack = { this . handleCreateBack . bind ( this ) } allCat = { this . state . allCat } /> } />
352
- < Route exact path = '/Admin/Challenges/Edit' render = { ( props ) => < AdminChallengeEdit { ...props } allCat = { this . state . allCat } challengeName = { this . state . challengeName } handleEditBack = { this . handleEditBack . bind ( this ) } handleEditChallBack = { this . handleEditChallBack . bind ( this ) } /> } />
333
+ < Divider />
334
+ < h1 style = { { fontSize : "150%" } } > Category Management { this . state . transferDisabled && ( < LoadingOutlined style = { { color : "#177ddc" } } /> ) } </ h1 >
335
+
336
+ < Transfer
337
+ dataSource = { this . state . allCat }
338
+ titles = { [ 'Visible Categories' , 'Hidden Categories' ] }
339
+ targetKeys = { this . state . targetKeys }
340
+ selectedKeys = { this . state . selectedKeys }
341
+ onChange = { this . handleChange }
342
+ onSelectChange = { this . handleSelectChange }
343
+ render = { item => item . key }
344
+ pagination
345
+ disabled = { this . state . transferDisabled }
346
+ />
353
347
354
- </ Switch >
348
+ < Divider / >
355
349
356
350
357
351
358
352
</ div >
359
353
) }
360
354
355
+
356
+ < Switch >
357
+ < Route exact path = '/Admin/Challenges/Create' render = { ( props ) => < AdminChallengeCreate { ...props } handleBack = { this . handleBack . bind ( this ) } handleCreateBack = { this . handleCreateBack . bind ( this ) } allCat = { this . state . allCat } /> } />
358
+ < Route exact path = '/Admin/Challenges/Edit' render = { ( props ) => < AdminChallengeEdit { ...props } allCat = { this . state . allCat } challengeName = { this . state . challengeName } handleEditBack = { this . handleEditBack . bind ( this ) } handleEditChallBack = { this . handleEditChallBack . bind ( this ) } /> } />
359
+
360
+ </ Switch >
361
+
361
362
</ Layout >
362
363
) ;
363
364
}
0 commit comments