summaryrefslogtreecommitdiff
path: root/view
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-04-13 23:48:00 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-04-13 23:48:00 +0200
commitc3b66fc95102b36bf21eacdc960183216683c270 (patch)
tree76b94129c680dd67979e44bf2adf48213513a0d3 /view
parent5e12dabced6ce55031f5c7f13afb15048d03edcd (diff)
Show timer, set time on create
Diffstat (limited to 'view')
-rw-r--r--view/main.templ1
-rw-r--r--view/main_templ.go2
-rw-r--r--view/timer.templ18
-rw-r--r--view/timer_templ.go53
-rw-r--r--view/timers_list.templ2
-rw-r--r--view/timers_list_templ.go4
6 files changed, 68 insertions, 12 deletions
diff --git a/view/main.templ b/view/main.templ
index b6d94d8..64a365c 100644
--- a/view/main.templ
+++ b/view/main.templ
@@ -6,6 +6,7 @@ templ Main(contents templ.Component) {
<head>
<title>Cool timer app</title>
<link rel="stylesheet" href="/static/style.css" />
+ <script type="module" src="/static/ui-components.js"></script>
<script src="/static/htmx.min.js"></script>
<script src="/static/response-targets.js"></script>
</head>
diff --git a/view/main_templ.go b/view/main_templ.go
index 109be9c..5b3831d 100644
--- a/view/main_templ.go
+++ b/view/main_templ.go
@@ -23,7 +23,7 @@ func Main(contents templ.Component) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html><head><title>Cool timer app</title><link rel=\"stylesheet\" href=\"/static/style.css\"><script src=\"/static/htmx.min.js\"></script><script src=\"/static/response-targets.js\"></script></head><body hx-boost=\"true\" hx-ext=\"response-targets\">")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html><head><title>Cool timer app</title><link rel=\"stylesheet\" href=\"/static/style.css\"><script type=\"module\" src=\"/static/ui-components.js\"></script><script src=\"/static/htmx.min.js\"></script><script src=\"/static/response-targets.js\"></script></head><body hx-boost=\"true\" hx-ext=\"response-targets\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/timer.templ b/view/timer.templ
index fa258eb..8d20933 100644
--- a/view/timer.templ
+++ b/view/timer.templ
@@ -7,6 +7,20 @@ import (
templ TimerView(timer model.Timer) {
<h1>This is timer { timer.Name } </h1>
<p><a href="/">Back to list</a></p>
- <p>Start time: { timer.StartTime.String() }</p>
- <p>End time: { timer.EndTime.String() }</p>
+ <p>Start time: <local-date>{ timer.StartTime.AsUTCString() }</local-date></p>
+ <p>End time: <local-date>{ timer.EndTime.AsUTCString() }</local-date></p>
+ <p>
+ Total time:
+ <timer-countdown
+ start={ timer.StartTime.AsUTCString() }
+ end={ timer.EndTime.AsUTCString() }
+ ></timer-countdown>
+ </p>
+ <p>
+ Remaining time:
+ <timer-countdown
+ end={ timer.EndTime.AsUTCString() }
+ ></timer-countdown>
+ </p>
}
+
diff --git a/view/timer_templ.go b/view/timer_templ.go
index 7fee7d3..55e5346 100644
--- a/view/timer_templ.go
+++ b/view/timer_templ.go
@@ -40,33 +40,72 @@ func TimerView(timer model.Timer) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><p><a href=\"/\">Back to list</a></p><p>Start time: ")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><p><a href=\"/\">Back to list</a></p><p>Start time: <local-date>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
- templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(timer.StartTime.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: 45}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 10, Col: 62}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p><p>End time: ")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</local-date></p><p>End time: <local-date>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
- templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(timer.EndTime.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: 41}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timer.templ`, Line: 11, Col: 58}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</local-date></p><p>Total time:\r <timer-countdown start=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ 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}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" end=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ 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}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></timer-countdown></p><p>Remaining time:\r <timer-countdown end=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ 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}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></timer-countdown></p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/view/timers_list.templ b/view/timers_list.templ
index 2d71a52..92d7013 100644
--- a/view/timers_list.templ
+++ b/view/timers_list.templ
@@ -25,6 +25,8 @@ templ TimerCreateForm(timerName string, err string) {
>
<p>
<input type="text" name="timerName" value={ timerName } placeholder="Name" />
+ <input type="number" name="days" placeholder="Days" style="width: 5em;" />
+ <input type="number" name="hours" placeholder="Hours" style="width: 5em;" />
<button type="submit">Create</button>
</p>
if err != "" {
diff --git a/view/timers_list_templ.go b/view/timers_list_templ.go
index af4922d..955ab9a 100644
--- a/view/timers_list_templ.go
+++ b/view/timers_list_templ.go
@@ -100,7 +100,7 @@ func TimerCreateForm(timerName string, err string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" placeholder=\"Name\"> <button type=\"submit\">Create</button></p>")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" placeholder=\"Name\"> <input type=\"number\" name=\"days\" placeholder=\"Days\" style=\"width: 5em;\"> <input type=\"number\" name=\"hours\" placeholder=\"Hours\" style=\"width: 5em;\"> <button type=\"submit\">Create</button></p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -112,7 +112,7 @@ func TimerCreateForm(timerName string, err string) templ.Component {
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(err)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timers_list.templ`, Line: 31, Col: 34}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `view\timers_list.templ`, Line: 33, Col: 34}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {