Skip to content

Commit 198617d

Browse files
authored
Merge pull request #104 from pgulb/98-make-flush-stats-more-brief
fix update button hiding/showing, changes to flushes divs
2 parents 2e1ee50 + bf7d42a commit 198617d

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

pwa/flush/components.go

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ func (b *RootContainer) OnMount(ctx app.Context) {
113113
ctx.Dispatch(func(ctx app.Context) {
114114
if !more {
115115
log.Println("*** Hiding update button...")
116-
Hide("update-button")
116+
b.buttonUpdate.Visible = false
117117
} else {
118118
log.Println("*** Showing update button...")
119-
app.Window().GetElementByID("update-button").Set("className", LoadFlushesButtonCss)
119+
b.buttonUpdate.Visible = true
120120
}
121121
if err != nil {
122122
ShowErrorDiv(ctx, err, 2)
@@ -184,12 +184,17 @@ func (b *RootContainer) GetList() app.UI {
184184

185185
type buttonUpdate struct {
186186
app.Compo
187-
parent *RootContainer
187+
parent *RootContainer
188+
Visible bool
188189
}
189190

190191
func (b *buttonUpdate) Render() app.UI {
192+
cls := InviCss
193+
if b.Visible {
194+
cls = LoadFlushesButtonCss
195+
}
191196
return app.Button().Text("Load More").OnClick(b.onClick).Class(
192-
LoadFlushesButtonCss).ID("update-button")
197+
cls).ID("update-button")
193198
}
194199
func (b *buttonUpdate) onClick(ctx app.Context, e app.Event) {
195200
ShowLoading("flushes-loading-update")
@@ -199,10 +204,10 @@ func (b *buttonUpdate) onClick(ctx app.Context, e app.Event) {
199204
ctx.Dispatch(func(ctx app.Context) {
200205
if !more {
201206
log.Println("*** Hiding update button...")
202-
Hide("update-button")
207+
b.Visible = false
203208
} else {
204209
log.Println("*** Showing update button...")
205-
app.Window().GetElementByID("update-button").Set("className", LoadFlushesButtonCss)
210+
b.Visible = true
206211
}
207212
defer Hide("flushes-loading-update")
208213
if result == nil {
@@ -553,19 +558,19 @@ func FlushTable(flushes []Flush) app.UI {
553558
divs = append(divs,
554559
app.Div().Body(
555560
timeDiv(flush),
556-
app.P().Text("Rating: "+strconv.Itoa(flush.Rating)),
561+
app.P().Text(strconv.Itoa(flush.Rating)+" ⭐"),
562+
app.If(flush.PhoneUsed, func() app.UI {
563+
return app.P().Text("📱 used")
564+
}),
565+
app.If(flush.Note != "", func() app.UI {
566+
return app.P().Text("Note: " + flush.Note).Class("break-all italic")
567+
}),
557568
app.Div().Body(
558569
&EditFlushButton{ID: flush.ID},
559570
&RemoveFlushButton{ID: flush.ID},
560571
&ConfirmRemoveFlushButton{ID: flush.ID},
561572
&CancelRemoveFlushButton{ID: flush.ID},
562573
).Class("max-w-1/6 remove-flush-buttonz-div"),
563-
app.If(flush.PhoneUsed, func() app.UI {
564-
return app.P().Text("Phone used")
565-
}),
566-
app.If(flush.Note != "", func() app.UI {
567-
return app.P().Text("Note: " + flush.Note).Class("break-all italic")
568-
}),
569574
).Class("flex flex-col p-4 border-1 shadow-lg rounded-lg shadow-amber-800").ID("div-"+flush.ID),
570575
)
571576
}
@@ -579,19 +584,16 @@ func timeDiv(flush Flush) app.UI {
579584
0,
580585
64,
581586
)
582-
if flush.TimeStart.Day() == flush.TimeEnd.Day() {
583-
return app.Div().Body(
584-
app.P().Text("🧻 ").Class("font-bold inline"),
585-
app.P().Text(flushDuration+" minutes, "+flush.TimeStart.Format(
586-
"2006-01-02 15:04")+"-"+flush.TimeEnd.Format("15:04")).Class("inline"),
587-
)
588-
} else {
589-
return app.Div().Body(
590-
app.P().Text("Time: ").Class("font-bold inline"),
591-
app.P().Text(flushDuration+" minutes, "+flush.TimeStart.Format(
592-
"2006-01-02 15:04")+" - "+flush.TimeEnd.Format("2006-01-02 15:04")).Class("inline"),
593-
)
587+
timeFmt := "15:04"
588+
if flush.TimeStart.Day() != flush.TimeEnd.Day() {
589+
timeFmt = "2006-01-02 15:04"
594590
}
591+
return app.Div().Body(
592+
app.P().Text("🧻 ").Class("font-bold inline"),
593+
app.P().
594+
Text(flushDuration+" min, 📅 "+flush.TimeStart.Format("2006-01-02 15:04")+" - "+flush.TimeEnd.Format(timeFmt)).
595+
Class("inline"),
596+
)
595597
}
596598

597599
type RemoveFlushButton struct {
@@ -989,13 +991,14 @@ func StatsDiv(ctx app.Context) (app.UI, error) {
989991
return nil, err
990992
}
991993
return app.Div().Body(
992-
app.P().Text("Total flushes: "+strconv.Itoa(stats.FlushCount)),
993-
app.P().Text("Total time: "+strconv.Itoa(stats.TotalTime)+" minutes"),
994-
app.P().Text("Mean time: "+strconv.Itoa(stats.MeanTime)+" minutes"),
995-
app.P().Text("Mean rating: "+strconv.Itoa(stats.MeanRating)),
996-
app.P().Text("Times with phone used: "+strconv.Itoa(stats.PhoneUsedCount)),
997-
app.P().Text("Percent with phone used: "+strconv.Itoa(stats.PercentPhoneUsed)+"%"),
998-
).Class("flex flex-col p-4 border-1 shadow-lg rounded-lg font-bold shadow-amber-800"),
994+
app.P().Text("Total 🧻 -> "+strconv.Itoa(stats.FlushCount)),
995+
app.P().
996+
Text("Total ⏱️ -> "+strconv.Itoa(stats.TotalTime)+" min ("+strconv.Itoa(stats.MeanTime)+" min average)"),
997+
app.P().Text("Average ⭐ -> "+strconv.Itoa(stats.MeanRating)),
998+
app.P().
999+
Text("Times with 📱 -> "+strconv.Itoa(stats.PhoneUsedCount)+" ("+strconv.Itoa(stats.PercentPhoneUsed)+"%)"),
1000+
).
1001+
Class("flex flex-col p-4 border-1 shadow-lg rounded-lg font-bold shadow-amber-800"),
9991002
nil
10001003
}
10011004

@@ -1020,7 +1023,7 @@ func (c *GiveFeedbackContainer) Render() app.UI {
10201023
app.P().Text("Feedback").Class("font-bold"),
10211024
app.Br(),
10221025
app.Textarea().Placeholder("your feedback").ID(
1023-
"feedback-text").MaxLength(300).Class("p-2 rounded-lg").Rows(12).Cols(30),
1026+
"feedback-text").MaxLength(300).Class("p-2 rounded-lg").Rows(10).Cols(25),
10241027
app.Br(),
10251028
&SubmitFeedbackButton{},
10261029
&LoadingWidget{id: "new-feedback-loading"},

0 commit comments

Comments
 (0)