From 1e9b8d0fa114ce706c4fa05004991e516cbddcd7 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 14 Apr 2024 23:51:04 +0200 Subject: Add time to timer --- view/timer.templ | 53 +++++++++++++------- view/timer_templ.go | 142 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 170 insertions(+), 25 deletions(-) (limited to 'view') diff --git a/view/timer.templ b/view/timer.templ index 8d20933..a447d01 100644 --- a/view/timer.templ +++ b/view/timer.templ @@ -1,26 +1,43 @@ package view import ( - "stevenlr.com/timer/model" + "fmt" + "stevenlr.com/timer/model" ) templ TimerView(timer model.Timer) { -

This is timer { timer.Name }

-

Back to list

-

Start time: { timer.StartTime.AsUTCString() }

-

End time: { timer.EndTime.AsUTCString() }

-

- Total time: - -

-

- Remaining time: - -

+
+

This is timer { timer.Name }

+

Back to list

+

Start time: { timer.StartTime.AsUTCString() }

+

End time: { timer.EndTime.AsUTCString() }

+

+ Total time: + +

+

+ Remaining time: + +

+ if !timer.IsFinished() { +

Add time

+

+ + + + + + + + + +

+ } +
} diff --git a/view/timer_templ.go b/view/timer_templ.go index 55e5346..1cafffd 100644 --- a/view/timer_templ.go +++ b/view/timer_templ.go @@ -11,6 +11,7 @@ import "io" import "bytes" import ( + "fmt" "stevenlr.com/timer/model" ) @@ -27,14 +28,14 @@ func TimerView(timer model.Timer) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

This is timer ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

This is timer ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(timer.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 8, Col: 34} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 10, Col: 32} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -47,7 +48,7 @@ func TimerView(timer model.Timer) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, 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: 10, Col: 62} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 12, Col: 60} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -60,7 +61,7 @@ func TimerView(timer model.Timer) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, 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: 11, Col: 58} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 13, Col: 56} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -73,7 +74,7 @@ func TimerView(timer model.Timer) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, 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: 15, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 17, Col: 41} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -86,7 +87,7 @@ func TimerView(timer model.Timer) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, 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: 16, Col: 45} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 18, Col: 37} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -99,7 +100,7 @@ func TimerView(timer model.Timer) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, 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: 22, Col: 45} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 24, Col: 37} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -109,6 +110,133 @@ func TimerView(timer model.Timer) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + if !timer.IsFinished() { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Add time

") + 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