From 6dbad4dbc8702e3e09de118e17ceadae201a66f3 Mon Sep 17 00:00:00 2001
From: Steven Le Rouzic
Date: Tue, 16 Apr 2024 23:34:20 +0200
Subject: Rework addTime
---
view/timer.templ | 85 +++++++++++-------
view/timer_templ.go | 250 ++++++++++++++++++++++++++++------------------------
2 files changed, 188 insertions(+), 147 deletions(-)
(limited to 'view')
diff --git a/view/timer.templ b/view/timer.templ
index 76bd7ba..45194c5 100644
--- a/view/timer.templ
+++ b/view/timer.templ
@@ -21,41 +21,60 @@ templ TimerTokenForm(timer model.Timer) {
}
+func renderTimeString(value int, unit string) string {
+ s := ""
+ if value > 1 { s = "s" }
+ return fmt.Sprint(value, " ", unit, s)
+}
+
+templ timeButton(id model.UUID, value int, unit string) {
+
+
+}
+
+templ TimerInfo(timer model.Timer) {
+ Timer "{ timer.Name }"
+ Back to list
+ Start time: { timer.StartTime.AsUTCString() }
+ End time: { timer.EndTime.AsUTCString() }
+
+ Total time:
+
+
+
+ Remaining time:
+
+
+}
+
templ TimerView(timer model.Timer) {
-
-
Timer "{ timer.Name }"
-
Back to list
-
Start time: { timer.StartTime.AsUTCString() }
-
End time: { timer.EndTime.AsUTCString() }
-
- Total time:
-
-
+
+ @TimerInfo(timer)
+
+ if !timer.IsFinished() {
+
Add time
- Remaining time:
-
+ @timeButton(timer.Id, 15, "minute")
+ @timeButton(timer.Id, 30, "minute")
+ @timeButton(timer.Id, 1, "hour")
+ @timeButton(timer.Id, 2, "hour")
+ @timeButton(timer.Id, 6, "hour")
+ @timeButton(timer.Id, 12, "hour")
+ @timeButton(timer.Id, 1, "day")
+ @timeButton(timer.Id, 1, "week")
+ @timeButton(timer.Id, 4, "week")
- if !timer.IsFinished() {
-
Add time
-
-
-
-
-
-
-
-
-
-
-
- }
-
API token
- @TimerTokenForm(timer)
-
+ }
+ API token
+ @TimerTokenForm(timer)
}
diff --git a/view/timer_templ.go b/view/timer_templ.go
index 35ca724..b606ab7 100644
--- a/view/timer_templ.go
+++ b/view/timer_templ.go
@@ -65,7 +65,15 @@ func TimerTokenForm(timer model.Timer) templ.Component {
})
}
-func TimerView(timer model.Timer) templ.Component {
+func renderTimeString(value int, unit string) string {
+ s := ""
+ if value > 1 {
+ s = "s"
+ }
+ return fmt.Sprint(value, " ", unit, s)
+}
+
+func timeButton(id model.UUID, value int, unit string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@@ -78,55 +86,118 @@ func TimerView(timer model.Timer) templ.Component {
templ_7745c5c3_Var4 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Timer \"")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if !templ_7745c5c3_IsBuffer {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
+ }
+ return templ_7745c5c3_Err
+ })
+}
+
+func TimerInfo(timer model.Timer) templ.Component {
+ return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
+ if !templ_7745c5c3_IsBuffer {
+ templ_7745c5c3_Buffer = templ.GetBuffer()
+ defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var8 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var8 == nil {
+ templ_7745c5c3_Var8 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Timer \"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var9 string
+ templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(timer.Name)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 40, Col: 24}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"
Back to list
Start time: ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var10 string
+ templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(timer.StartTime.AsUTCString())
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 42, Col: 59}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
End time: ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var11 string
+ templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(timer.EndTime.AsUTCString())
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 43, Col: 55}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Total time:\r ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = TimerInfo(timer).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
if !timer.IsFinished() {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Add time
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -291,10 +317,6 @@ func TimerView(timer model.Timer) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
--
cgit