@@ -67,15 +67,15 @@ class ModPackOverview extends React.Component {
6767 } ,
6868 showLoaderOnConfirm : true ,
6969 preConfirm : ( inputValue ) => {
70- // console.log(this);
71-
72- $ . ajax ( {
70+ // TODO remove jquery Ajax, use react one, return Promise from fetch
71+ return new Promise ( ( resolve , reject ) => $ . ajax ( {
7372 url : "/api/mods/packs/create" ,
7473 method : "POST" ,
7574 data : { name : inputValue } ,
7675 dataType : "JSON" ,
7776 success : ( data ) => {
7877 this . mutex . lock ( ( ) => {
78+ resolve ( ) ;
7979 let packList = this . state . listPacks ;
8080
8181 data . data . mod_packs . forEach ( ( v , k ) => {
@@ -91,24 +91,25 @@ class ModPackOverview extends React.Component {
9191
9292 ReactSwalNormal . fire ( {
9393 title : "modpack created successfully" ,
94- type : "success"
94+ icon : "success"
9595 } ) ;
9696
9797 this . mutex . unlock ( ) ;
9898 } ) ;
9999 } ,
100100 error : ( jqXHR , status , err ) => {
101+ reject ( ) ;
101102 console . log ( 'api/mods/packs/create' , status , err . toString ( ) ) ;
102103
103104 let jsonResponse = jqXHR . responseJSON ;
104105
105106 ReactSwalNormal . fire ( {
106107 title : "Error on creating modpack" ,
107108 text : jsonResponse . data ,
108- type : "error"
109+ icon : "error"
109110 } ) ;
110111 }
111- } ) ;
112+ } ) ) ;
112113 }
113114 } ) ;
114115 }
@@ -121,18 +122,20 @@ class ModPackOverview extends React.Component {
121122 ReactSwalDanger . fire ( {
122123 title : "Are you sure?" ,
123124 html : < p > You really want to delete this modpack?< br /> There is no turning back, the modpack will be deleted forever (a very long time)!</ p > ,
124- type : "question" ,
125+ icon : "question" ,
125126 showCancelButton : true ,
126127 showLoaderOnConfirm : true ,
127128 preConfirm : ( ) => {
128- $ . ajax ( {
129+ // TODO remove jquery Ajax, use react one, return Promise from fetch
130+ return new Promise ( ( resolve , reject ) => $ . ajax ( {
129131 url : "/api/mods/packs/delete" ,
130132 method : "POST" ,
131133 data : { name : name } ,
132134 dataType : "JSON" ,
133135 success : ( data ) => {
134136 if ( data . success ) {
135137 this . mutex . lock ( ( ) => {
138+ resolve ( ) ;
136139 let modPacks = this . state . listPacks ;
137140
138141 modPacks . forEach ( ( v , k ) => {
@@ -147,14 +150,15 @@ class ModPackOverview extends React.Component {
147150
148151 ReactSwalNormal . fire ( {
149152 title : "Modpack deleted successfully" ,
150- type : "success"
153+ icon : "success"
151154 } ) ;
152155
153156 this . mutex . unlock ( ) ;
154157 } ) ;
155158 }
156159 } ,
157160 error : ( jqXHR , status , err ) => {
161+ reject ( ) ;
158162 console . log ( 'api/mods/packs/delete' , status , err . toString ( ) ) ;
159163
160164 let jsonResponse = jqXHR . responseJSON || err . toString ( ) ;
@@ -163,10 +167,10 @@ class ModPackOverview extends React.Component {
163167 ReactSwalNormal . fire ( {
164168 title : "Error on creating modpack" ,
165169 text : jsonResponse ,
166- type : "error"
170+ icon : "error"
167171 } ) ;
168172 }
169- } )
173+ } ) ) ;
170174 }
171175 } ) ;
172176 }
@@ -179,26 +183,29 @@ class ModPackOverview extends React.Component {
179183 ReactSwalDanger . fire ( {
180184 title : "Are you sure?" ,
181185 text : "This operation will replace the current installed mods with the mods out of the selected ModPack!" ,
182- type : "question" ,
186+ icon : "question" ,
183187 showCancelButton : true ,
184188 showLoaderOnConfirm : true ,
185189 preConfirm : ( ) => {
186- $ . ajax ( {
190+ // TODO remove jquery Ajax, use react one, return Promise from fetch
191+ return new Promise ( ( resolve , reject ) => $ . ajax ( {
187192 url : "/api/mods/packs/load" ,
188193 method : "POST" ,
189194 data : { name : name } ,
190195 dataType : "JSON" ,
191196 success : ( data ) => {
197+ resolve ( ) ;
192198 ReactSwalNormal . fire ( {
193199 title : "ModPack loaded!" ,
194- type : "success"
200+ icon : "success"
195201 } ) ;
196202
197203 this . props . modContentClass . setState ( {
198204 installedMods : data . data . mods
199205 } ) ;
200206 } ,
201207 error : ( jqXHR , status , err ) => {
208+ reject ( ) ;
202209 console . log ( 'api/mods/packs/load' , status , err . toString ( ) ) ;
203210
204211 let jsonResponse = jqXHR . responseJSON || err . toString ( ) ;
@@ -207,10 +214,10 @@ class ModPackOverview extends React.Component {
207214 ReactSwalNormal . fire ( {
208215 title : "Error on loading ModPack" ,
209216 text : jsonResponse ,
210- type : "error"
217+ icon : "error"
211218 } ) ;
212219 }
213- } )
220+ } ) ) ;
214221 }
215222 } ) ;
216223 }
@@ -227,7 +234,7 @@ class ModPackOverview extends React.Component {
227234 ReactSwalNormal . fire ( {
228235 title : "Toggle mod failed" ,
229236 text : "Can't toggle the mod, when an update is still in progress" ,
230- type : "error"
237+ icon : "error"
231238 } ) ;
232239 return false ;
233240 }
@@ -274,7 +281,7 @@ class ModPackOverview extends React.Component {
274281 ReactSwalNormal . fire ( {
275282 title : "Toggle Mod went wrong" ,
276283 text : err . toString ( ) ,
277- type : "error"
284+ icon : "error"
278285 } ) ;
279286 }
280287 } ) ;
@@ -287,7 +294,7 @@ class ModPackOverview extends React.Component {
287294 ReactSwalNormal . fire ( {
288295 title : "Delete failed" ,
289296 text : "Can't delete the mod, when an update is still in progress" ,
290- type : "error"
297+ icon : "error"
291298 } ) ;
292299 return false ;
293300 }
@@ -300,13 +307,14 @@ class ModPackOverview extends React.Component {
300307 ReactSwalDanger . fire ( {
301308 title : "Delete Mod?" ,
302309 text : "This will delete the mod forever" ,
303- type : "question" ,
310+ icon : "question" ,
304311 showCancelButton : true ,
305312 confirmButtonText : "Delete it!" ,
306313 cancelButtonText : "Close" ,
307314 showLoaderOnConfirm : true ,
308315 preConfirm : ( ) => {
309- $ . ajax ( {
316+ // TODO remove jquery Ajax, use react one, return Promise from fetch
317+ return new Promise ( ( resolve , reject ) => $ . ajax ( {
310318 url : "/api/mods/packs/mod/delete" ,
311319 method : "POST" ,
312320 data : {
@@ -317,9 +325,10 @@ class ModPackOverview extends React.Component {
317325 success : ( data ) => {
318326 if ( data . success ) {
319327 this . mutex . lock ( ( ) => {
328+ resolve ( ) ;
320329 ReactSwalNormal . fire ( {
321330 title : < p > Delete of mod { modName } inside modPack { modPackName } successful</ p > ,
322- type : "success"
331+ icon : "success"
323332 } )
324333
325334 let packList = this . state . listPacks ;
@@ -344,14 +353,15 @@ class ModPackOverview extends React.Component {
344353 }
345354 } ,
346355 error : ( jqXHR , status , err ) => {
356+ reject ( ) ;
347357 console . log ( 'api/mods/packs/mod/delete' , status , err . toString ( ) ) ;
348358 ReactSwalNormal . fire ( {
349359 title : "Delete Mod went wrong" ,
350360 text : jqXHR . responseJSON . data ,
351- type : "error"
361+ icon : "error"
352362 } ) ;
353363 }
354- } ) ;
364+ } ) ) ;
355365 }
356366 } ) ;
357367 }
@@ -363,7 +373,7 @@ class ModPackOverview extends React.Component {
363373 ReactSwalNormal . fire ( {
364374 title : "Update failed" ,
365375 text : "please login into Factorio to update mod" ,
366- type : "error" ,
376+ icon : "error" ,
367377 } ) ;
368378
369379 let $addModBox = $ ( '#add-mod-box' ) ;
@@ -423,7 +433,7 @@ class ModPackOverview extends React.Component {
423433 ReactSwalNormal . fire ( {
424434 title : "Update Mod went wrong" ,
425435 text : jqXHR . responseJSON . data ,
426- type : "error"
436+ icon : "error"
427437 } ) ;
428438 }
429439 } ) ;
0 commit comments