@@ -88,6 +88,7 @@ func (r *RegisterContainer) Render() app.UI {
88
88
type RootContainer struct {
89
89
app.Compo
90
90
buttonUpdate
91
+ Stats app.UI
91
92
FlushList app.UI
92
93
}
93
94
@@ -104,15 +105,21 @@ func (b *RootContainer) OnMount(ctx app.Context) {
104
105
app .Window ().GetElementByID ("about-container" ).Set ("className" , "invisible fixed" )
105
106
ShowLoading ("flushes-loading" )
106
107
ctx .Async (func () {
108
+ stats , err := StatsDiv (ctx )
107
109
result := GetFlushesFromOID (ctx )
108
110
ctx .Dispatch (func (ctx app.Context ) {
111
+ if err != nil {
112
+ ShowErrorDiv (ctx , err , 2 )
113
+ return
114
+ }
109
115
defer Hide ("flushes-loading" )
110
116
if result == nil {
111
117
ShowErrorDiv (ctx , errors .New ("Error while fetching flushes" ), 2 )
112
118
return
113
119
}
114
120
app .Window ().GetElementByID ("hidden-hello" ).Set ("innerHTML" , "hello!" )
115
121
b .SetList (result )
122
+ b .Stats = stats
116
123
var isEmpty string
117
124
ctx .GetState ("no-flushes" , & isEmpty )
118
125
log .Println ("no-flushes: " , isEmpty )
@@ -151,6 +158,7 @@ func (b *RootContainer) Render() app.UI {
151
158
).ID ("root-buttons-container" ).Class (InviCss ),
152
159
app .P ().Text ("Tracked flushes:" ).Class ("py-2" ),
153
160
& LoadingWidget {id : "flushes-loading" },
161
+ b .Stats ,
154
162
b .FlushList ,
155
163
app .Div ().Body (
156
164
& b .buttonUpdate ,
@@ -559,20 +567,6 @@ func FlushTable(flushes []Flush, ctx app.Context) app.UI {
559
567
).Class ("flex flex-col p-4 border-1 shadow-lg rounded-lg" ).ID ("div-" + flush .ID ),
560
568
)
561
569
}
562
- stats , err := GetStats (ctx )
563
- if err != nil {
564
- ShowErrorDiv (ctx , err , 3 )
565
- return app .Div ()
566
- }
567
- statsDiv := app .Div ().Body (
568
- app .P ().Text ("Total flushes: " + strconv .Itoa (stats .FlushCount )),
569
- app .P ().Text ("Total time: " + strconv .Itoa (stats .TotalTime )+ " minutes" ),
570
- app .P ().Text ("Mean time: " + strconv .Itoa (stats .MeanTime )+ " minutes" ),
571
- app .P ().Text ("Mean rating: " + strconv .Itoa (stats .MeanRating )),
572
- app .P ().Text ("Times with phone used: " + strconv .Itoa (stats .PhoneUsedCount )),
573
- app .P ().Text ("Percent with phone used: " + strconv .Itoa (stats .PercentPhoneUsed )+ "%" ),
574
- ).Class ("flex flex-col p-4 border-1 shadow-lg rounded-lg font-bold" )
575
- divs = append ([]app.UI {statsDiv }, divs ... )
576
570
return app .Div ().Body (divs ... )
577
571
}
578
572
@@ -987,3 +981,19 @@ func (b *BurgerMenuButton) OnClick(ctx app.Context, e app.Event) {
987
981
app .Window ().GetElementByID ("root-buttons-container" ).Set ("className" , RootButtonsCss )
988
982
}
989
983
}
984
+
985
+ func StatsDiv (ctx app.Context ) (app.UI , error ) {
986
+ stats , err := GetStats (ctx )
987
+ if err != nil {
988
+ return nil , err
989
+ }
990
+ return app .Div ().Body (
991
+ app .P ().Text ("Total flushes: " + strconv .Itoa (stats .FlushCount )),
992
+ app .P ().Text ("Total time: " + strconv .Itoa (stats .TotalTime )+ " minutes" ),
993
+ app .P ().Text ("Mean time: " + strconv .Itoa (stats .MeanTime )+ " minutes" ),
994
+ app .P ().Text ("Mean rating: " + strconv .Itoa (stats .MeanRating )),
995
+ app .P ().Text ("Times with phone used: " + strconv .Itoa (stats .PhoneUsedCount )),
996
+ app .P ().Text ("Percent with phone used: " + strconv .Itoa (stats .PercentPhoneUsed )+ "%" ),
997
+ ).Class ("flex flex-col p-4 border-1 shadow-lg rounded-lg font-bold" ),
998
+ nil
999
+ }
0 commit comments