diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-16 23:34:20 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-16 23:34:20 +0200 |
commit | 6dbad4dbc8702e3e09de118e17ceadae201a66f3 (patch) | |
tree | 55162396f2f0cc582e583e03eebc5974693bbb9e /view/timer.templ | |
parent | 13a85f42183b7373296fa85319d33f1359feaea9 (diff) |
Rework addTime
Diffstat (limited to 'view/timer.templ')
-rw-r--r-- | view/timer.templ | 85 |
1 files changed, 52 insertions, 33 deletions
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) { </p>
}
+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) {
+ <button
+ hx-target=".timer-info"
+ hx-post={ fmt.Sprint("/timer/", id, "/addTime") }
+ hx-include="next input"
+ >{ renderTimeString(value, unit) }</button>
+ <input type="hidden" name="timeToAdd" value={ fmt.Sprint(value, "", unit[:1]) } />
+}
+
+templ TimerInfo(timer model.Timer) {
+ <h1>Timer "{ timer.Name }"</h1>
+ <p><a href="/">Back to list</a></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>
+}
+
templ TimerView(timer model.Timer) {
- <div class="timer">
- <h1>Timer "{ timer.Name }"</h1>
- <p><a href="/">Back to list</a></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>
+ <div class="timer-info">
+ @TimerInfo(timer)
+ </div>
+ if !timer.IsFinished() {
+ <h3>Add time</h3>
<p>
- Remaining time:
- <timer-countdown
- end={ timer.EndTime.AsUTCString() }
- ></timer-countdown>
+ @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")
</p>
- if !timer.IsFinished() {
- <h3>Add time</h3>
- <p>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/15m") }>15 minutes</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/30m") }>30 minutes</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/1h") }>1 hour</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/2h") }>2 hours</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/6h") }>6 hours</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/12h") }>12 hours</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/1d") }>1 day</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/1w") }>1 week</button>
- <button hx-target="closest .timer" hx-post={ fmt.Sprint("/timer/", timer.Id, "/addTime/4w") }>4 weeks</button>
- </p>
- }
- <h3>API token</h3>
- @TimerTokenForm(timer)
- </div>
+ }
+ <h3>API token</h3>
+ @TimerTokenForm(timer)
}
|