@@ -250,31 +250,33 @@ func (b *buttonLogin) onClick(ctx app.Context, e app.Event) {
250
250
return
251
251
}
252
252
ctx .Async (func () {
253
- defer Hide ("login-loading" )
254
253
status , basic_auth , err := TryLogin (user , pass )
255
254
if err != nil {
256
255
ShowErrorDiv (ctx , err , 1 )
257
256
return
258
257
}
259
- switch status {
260
- case 200 :
261
- ctx .SetState ("creds" , Creds {
262
- UserColonPass : basic_auth ,
263
- LoggedIn : true ,
264
- }).ExpiresIn (time .Second * time .Duration (loginSeconds )).PersistWithEncryption ()
265
- log .Printf ("Logged in as %s\n for %v seconds!" , user , loginSeconds )
266
- app .Window ().Set ("location" , "." )
267
- ctx .DelState ("lastUsedCreds" )
268
- case 401 :
269
- ShowErrorDiv (ctx , errors .New ("invalid credentials" ), 1 )
270
- ctx .SetState ("lastUsedCreds" , LastTriedCreds {
271
- User : user ,
272
- Password : pass ,
273
- }).ExpiresIn (time .Second * 10 )
274
- default :
275
- ShowErrorDiv (ctx , errors .New ("login failed" ), 1 )
276
- ctx .DelState ("lastUsedCreds" )
277
- }
258
+ ctx .Dispatch (func (ctx app.Context ) {
259
+ defer Hide ("login-loading" )
260
+ switch status {
261
+ case 200 :
262
+ ctx .SetState ("creds" , Creds {
263
+ UserColonPass : basic_auth ,
264
+ LoggedIn : true ,
265
+ }).ExpiresIn (time .Second * time .Duration (loginSeconds )).PersistWithEncryption ()
266
+ log .Printf ("Logged in as %s\n for %v seconds!" , user , loginSeconds )
267
+ app .Window ().Set ("location" , "." )
268
+ ctx .DelState ("lastUsedCreds" )
269
+ case 401 :
270
+ ShowErrorDiv (ctx , errors .New ("invalid credentials" ), 1 )
271
+ ctx .SetState ("lastUsedCreds" , LastTriedCreds {
272
+ User : user ,
273
+ Password : pass ,
274
+ }).ExpiresIn (time .Second * 10 )
275
+ default :
276
+ ShowErrorDiv (ctx , errors .New ("login failed" ), 1 )
277
+ ctx .DelState ("lastUsedCreds" )
278
+ }
279
+ })
278
280
})
279
281
}
280
282
@@ -299,30 +301,32 @@ func (b *buttonRegister) onClick(ctx app.Context, e app.Event) {
299
301
return
300
302
}
301
303
ctx .Async (func () {
302
- defer Hide ("register-loading" )
303
304
status , basic_auth , err := TryRegister (user , pass )
304
305
log .Println ("register status code: " , status )
305
306
if err != nil {
306
307
ShowErrorDiv (ctx , err , 1 )
307
308
}
308
- switch status {
309
- case 201 :
310
- ctx .SetState ("creds" , Creds {
311
- UserColonPass : basic_auth ,
312
- LoggedIn : true ,
313
- }).ExpiresIn (time .Second * time .Duration (604800 )).PersistWithEncryption ()
314
- ctx .DelState ("lastUsedCredsRegister" )
315
- app .Window ().Set ("location" , "." )
316
- case 422 :
317
- ShowBadRegisterCredsErr ()
318
- SetLastUsedCredsState (ctx , user , pass )
319
- case 409 :
320
- ShowErrorDiv (ctx , errors .New ("username already exists" ), 1 )
321
- SetLastUsedCredsState (ctx , user , pass )
322
- default :
323
- ShowErrorDiv (ctx , errors .New ("register failed" ), 1 )
324
- ctx .DelState ("lastUsedCredsRegister" )
325
- }
309
+ ctx .Dispatch (func (ctx app.Context ) {
310
+ defer Hide ("register-loading" )
311
+ switch status {
312
+ case 201 :
313
+ ctx .SetState ("creds" , Creds {
314
+ UserColonPass : basic_auth ,
315
+ LoggedIn : true ,
316
+ }).ExpiresIn (time .Second * time .Duration (604800 )).PersistWithEncryption ()
317
+ ctx .DelState ("lastUsedCredsRegister" )
318
+ app .Window ().Set ("location" , "." )
319
+ case 422 :
320
+ ShowBadRegisterCredsErr ()
321
+ SetLastUsedCredsState (ctx , user , pass )
322
+ case 409 :
323
+ ShowErrorDiv (ctx , errors .New ("username already exists" ), 1 )
324
+ SetLastUsedCredsState (ctx , user , pass )
325
+ default :
326
+ ShowErrorDiv (ctx , errors .New ("register failed" ), 1 )
327
+ ctx .DelState ("lastUsedCredsRegister" )
328
+ }
329
+ })
326
330
})
327
331
}
328
332
@@ -459,19 +463,21 @@ func (b *SubmitFlushButton) onClick(ctx app.Context, e app.Event) {
459
463
return
460
464
}
461
465
ctx .Async (func () {
462
- defer Hide ("new-flush-loading" )
463
466
statusCode , err := TryAddFlush (creds , flush )
464
467
log .Println ("Flush add statusCode: " , statusCode )
465
- if err != nil {
466
- ShowErrorDiv (ctx , err , 2 )
467
- return
468
- }
469
- switch statusCode {
470
- case 201 , 204 :
471
- app .Window ().Set ("location" , "." )
472
- default :
473
- ShowErrorDiv (ctx , errors .New ("Unexpected error while adding flush" ), 2 )
474
- }
468
+ ctx .Dispatch (func (ctx app.Context ) {
469
+ defer Hide ("new-flush-loading" )
470
+ if err != nil {
471
+ ShowErrorDiv (ctx , err , 2 )
472
+ return
473
+ }
474
+ switch statusCode {
475
+ case 201 , 204 :
476
+ app .Window ().Set ("location" , "." )
477
+ default :
478
+ ShowErrorDiv (ctx , errors .New ("Unexpected error while adding flush" ), 2 )
479
+ }
480
+ })
475
481
})
476
482
}
477
483
@@ -599,12 +605,12 @@ func (b *ConfirmRemoveFlushButton) onClick(ctx app.Context, e app.Event) {
599
605
log .Printf ("Confirm remove button pressed (%s)...\n " , b .ID )
600
606
log .Println ("removing flush " + b .ID + "..." )
601
607
ShowLoading ("flushes-loading" )
602
- defer Hide ("flushes-loading" )
603
608
ctx .Async (func () {
604
609
var creds Creds
605
610
ctx .GetState ("creds" , & creds )
606
611
err := RemoveFlush (b .ID , creds .UserColonPass )
607
612
ctx .Dispatch (func (ctx app.Context ) {
613
+ defer Hide ("flushes-loading" )
608
614
if err != nil {
609
615
ShowErrorDiv (ctx , err , 2 )
610
616
return
0 commit comments