@@ -16,6 +16,7 @@ const (
16
16
RegisterDivCss = "p-4 text-center text-xl shadow-lg bg-white rounded-lg mx-10"
17
17
InviCss = "fixed invisible"
18
18
RootContainerCss = "shadow-lg bg-white rounded-lg p-6 min-h-72 relative"
19
+ LoadingCss = "flex flex-row justify-center items-center"
19
20
)
20
21
21
22
type ErrorContainer struct {
@@ -68,6 +69,7 @@ func (r *RegisterContainer) Render() app.UI {
68
69
& buttonRegister {},
69
70
app .P ().Text ("" ).Class ("text-red-500" ).ID ("register-error" ),
70
71
).Class (InviCss ).ID ("register-container" ),
72
+ & LoadingWidget {id : "register-loading" },
71
73
)
72
74
}
73
75
@@ -92,6 +94,8 @@ func (b *RootContainer) OnMount(ctx app.Context) {
92
94
ShowErrorDiv (ctx , err , 1 )
93
95
return
94
96
}
97
+ ShowLoading ("flushes-loading" )
98
+ defer Hide ("flushes-loading" )
95
99
flushes , err := GetFlushes (ctx )
96
100
if err != nil {
97
101
ShowErrorDiv (ctx , err , 1 )
@@ -108,6 +112,7 @@ func (b *RootContainer) Render() app.UI {
108
112
app .H1 ().Text ("Flush Log" ).Class ("text-2xl" ),
109
113
& buttonLogout {},
110
114
app .P ().Text ("Tracked flushes:" ).Class ("py-2" ),
115
+ & LoadingWidget {id : "flushes-loading" },
111
116
b .FlushList ,
112
117
app .Div ().Body (
113
118
b .buttonUpdate .Render (),
@@ -144,6 +149,8 @@ func (b *buttonUpdate) onClick(ctx app.Context, e app.Event) {
144
149
ShowErrorDiv (ctx , err , 1 )
145
150
return
146
151
}
152
+ ShowLoading ("flushes-loading" )
153
+ defer Hide ("flushes-loading" )
147
154
flushes , err := GetFlushes (ctx )
148
155
if err != nil {
149
156
ShowErrorDiv (ctx , err , 1 )
@@ -180,6 +187,7 @@ func (l *LoginContainer) Render() app.UI {
180
187
& buttonLogin {},
181
188
& buttonShowRegister {},
182
189
),
190
+ & LoadingWidget {id : "login-loading" },
183
191
),
184
192
).Class ("p-4 text-center text-xl shadow-lg bg-white rounded-lg" ).ID ("login-container" ),
185
193
& RegisterContainer {},
@@ -198,6 +206,7 @@ func (b *buttonLogin) Render() app.UI {
198
206
func (b * buttonLogin ) onClick (ctx app.Context , e app.Event ) {
199
207
loginSeconds := 60
200
208
log .Println ("Trying to log in..." )
209
+ ShowLoading ("login-loading" )
201
210
if app .Window ().GetElementByID ("remember-me" ).Get ("checked" ).Bool () {
202
211
log .Println ("remember-me checked" )
203
212
loginSeconds = 604800 // week
@@ -207,10 +216,12 @@ func (b *buttonLogin) onClick(ctx app.Context, e app.Event) {
207
216
user , pass := GetLoginCreds ()
208
217
err := ValidateLoginCreds (user , pass , lastCreds )
209
218
if err != nil {
219
+ Hide ("login-loading" )
210
220
ShowErrorDiv (ctx , err , 1 )
211
221
return
212
222
}
213
223
ctx .Async (func () {
224
+ defer Hide ("login-loading" )
214
225
status , basic_auth , err := TryLogin (user , pass )
215
226
if err != nil {
216
227
ShowErrorDiv (ctx , err , 1 )
@@ -248,15 +259,18 @@ func (b *buttonRegister) Render() app.UI {
248
259
}
249
260
func (b * buttonRegister ) onClick (ctx app.Context , e app.Event ) {
250
261
log .Println ("Trying to register..." )
262
+ ShowLoading ("register-loading" )
251
263
lastCreds := LastTriedCreds {}
252
264
ctx .GetState ("lastUsedCredsRegister" , & lastCreds )
253
265
user , pass , repeatPass := GetRegisterCreds ()
254
266
err := ValidateRegistryCreds (user , pass , repeatPass , lastCreds )
255
267
if err != nil {
268
+ Hide ("register-loading" )
256
269
ShowErrorDiv (ctx , err , 1 )
257
270
return
258
271
}
259
272
ctx .Async (func () {
273
+ defer Hide ("register-loading" )
260
274
status , basic_auth , err := TryRegister (user , pass )
261
275
log .Println ("register status code: " , status )
262
276
if err != nil {
@@ -334,6 +348,7 @@ func (c *NewFlushContainer) Render() app.UI {
334
348
"new-flush-note" ).MaxLength (100 ),
335
349
app .Br (),
336
350
& SubmitFlushButton {},
351
+ & LoadingWidget {id : "new-flush-loading" },
337
352
).Class ("p-4 text-center text-xl shadow-lg bg-white rounded-lg" ),
338
353
app .Br (),
339
354
& LinkButton {Text : "Back to Home Screen" , Location : "." },
@@ -384,9 +399,11 @@ func (b *SubmitFlushButton) Render() app.UI {
384
399
}
385
400
func (b * SubmitFlushButton ) onClick (ctx app.Context , e app.Event ) {
386
401
var creds Creds
402
+ ShowLoading ("new-flush-loading" )
387
403
ctx .GetState ("creds" , & creds )
388
404
log .Println ("Logged in: " , creds .LoggedIn )
389
405
if ! creds .LoggedIn {
406
+ Hide ("new-flush-loading" )
390
407
app .Window ().Set ("location" , "login" )
391
408
return
392
409
}
@@ -397,15 +414,18 @@ func (b *SubmitFlushButton) onClick(ctx app.Context, e app.Event) {
397
414
app .Window ().GetElementByID ("new-flush-phone-used" ).Get ("checked" ).Bool (),
398
415
app .Window ().GetElementByID ("new-flush-note" ).Get ("value" ).String ())
399
416
if err != nil {
417
+ Hide ("new-flush-loading" )
400
418
ShowErrorDiv (ctx , err , 2 )
401
419
return
402
420
}
403
421
err = ValidateFlush (flush )
404
422
if err != nil {
423
+ Hide ("new-flush-loading" )
405
424
ShowErrorDiv (ctx , err , 1 )
406
425
return
407
426
}
408
427
ctx .Async (func () {
428
+ defer Hide ("new-flush-loading" )
409
429
statusCode , err := TryAddFlush (creds , flush )
410
430
log .Println ("Flush add statusCode: " , statusCode )
411
431
if err != nil {
@@ -444,9 +464,8 @@ func (a *AboutContainer) Render() app.UI {
444
464
Location : "login" ,
445
465
AdditionalCss : "hover:bg-yellow-700" ,
446
466
},
447
- ).
448
- ID ("about-container" ).Class ("flex flex-col p-4 shadow-lg rounded-lg" ),
449
- ).Class (CenteringDivCss )
467
+ ).Class ("flex flex-col p-4 shadow-lg rounded-lg" ),
468
+ ).Class (CenteringDivCss ).ID ("about-container" )
450
469
}
451
470
452
471
func FLushTable (flushes []Flush ) app.UI {
@@ -513,3 +532,19 @@ func timeDiv(flush Flush) app.UI {
513
532
)
514
533
}
515
534
}
535
+
536
+ type LoadingWidget struct {
537
+ app.Compo
538
+ id string
539
+ }
540
+
541
+ func (l * LoadingWidget ) Render () app.UI {
542
+ return app .Div ().Body (
543
+ app .Div ().Body (
544
+ app .Span ().
545
+ Text ("Loading..." ).Class ("font-bold text-black" ).
546
+ Class ("!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]" ),
547
+ ).
548
+ Class ("inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-e-transparent align-[-0.125em] text-surface motion-reduce:animate-[spin_1.5s_linear_infinite] text-yellow-500" ),
549
+ ).Class (InviCss ).ID (l .id )
550
+ }
0 commit comments