summaryrefslogtreecommitdiff
path: root/view
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-04-27 23:55:31 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-04-27 23:55:31 +0200
commita55cfe8205d5cb2fb0948c173f23ad71d6614d13 (patch)
tree386a341b3bcc543ca8ac7bfe7ff944cac669fe25 /view
parentdf3068728abacfc98fa19f3dba62b35f65aea731 (diff)
Rename everything to locker/lock
Diffstat (limited to 'view')
-rw-r--r--view/lock.templ80
-rw-r--r--view/locks_list.templ51
-rw-r--r--view/login.templ2
-rw-r--r--view/main.templ4
-rw-r--r--view/timer.templ80
-rw-r--r--view/timers_list.templ51
6 files changed, 134 insertions, 134 deletions
diff --git a/view/lock.templ b/view/lock.templ
new file mode 100644
index 0000000..4dd0516
--- /dev/null
+++ b/view/lock.templ
@@ -0,0 +1,80 @@
+package view
+
+import (
+ "fmt"
+ "stevenlr.com/locker/model"
+)
+
+templ LockTokenForm(lock model.Lock) {
+ <p class="token-form">
+ <button
+ type="button"
+ hx-post={ fmt.Sprint("/lock/", lock.Id, "/resetToken") }
+ hx-target="closest .token-form"
+ hx-confirm="Are you sure you want to reset the token for this lock?"
+ >Reset token</button>
+ <button
+ type="button"
+ hx-get={ fmt.Sprint("/lock/", lock.Id, "/token") }
+ hx-swap="outerHTML"
+ >Show token</button>
+ </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=".lock-info"
+ hx-post={ fmt.Sprint("/lock/", id, "/addTime") }
+ hx-include="next input"
+ >{ renderTimeString(value, unit) }</button>
+ <input type="hidden" name="timeToAdd" value={ fmt.Sprint(value, "", unit[:1]) } />
+}
+
+templ LockInfo(lock model.Lock) {
+ <h1>Lock "{ lock.Name }"</h1>
+ <p>Start time: <local-date>{ lock.StartTime.AsUTCString() }</local-date></p>
+ <p>End time: <local-date>{ lock.EndTime.AsUTCString() }</local-date></p>
+ <p>
+ Total time:
+ <lock-countdown
+ start={ lock.StartTime.AsUTCString() }
+ end={ lock.EndTime.AsUTCString() }
+ ></lock-countdown>
+ </p>
+ <p>
+ Remaining time:
+ <lock-countdown
+ end={ lock.EndTime.AsUTCString() }
+ ></lock-countdown>
+ </p>
+}
+
+templ LockView(lock model.Lock) {
+ <p><a href="/">Back to list</a></p>
+ <div class="lock-info">
+ @LockInfo(lock)
+ </div>
+ if !lock.IsFinished() {
+ <h3>Add time</h3>
+ <p>
+ @timeButton(lock.Id, 15, "minute")
+ @timeButton(lock.Id, 30, "minute")
+ @timeButton(lock.Id, 1, "hour")
+ @timeButton(lock.Id, 2, "hour")
+ @timeButton(lock.Id, 6, "hour")
+ @timeButton(lock.Id, 12, "hour")
+ @timeButton(lock.Id, 1, "day")
+ @timeButton(lock.Id, 1, "week")
+ @timeButton(lock.Id, 4, "week")
+ </p>
+ }
+ <h3>API token</h3>
+ @LockTokenForm(lock)
+}
+
diff --git a/view/locks_list.templ b/view/locks_list.templ
new file mode 100644
index 0000000..e940b88
--- /dev/null
+++ b/view/locks_list.templ
@@ -0,0 +1,51 @@
+package view
+
+import (
+ "stevenlr.com/locker/model"
+ "fmt"
+)
+
+templ lock(t model.Lock) {
+ <p class="lock-row">
+ <a href={ templ.URL(fmt.Sprint("/lock/", t.Id)) }>{ t.Name }</a>
+ -
+ <a
+ href="javascript:void(0);"
+ hx-delete={ fmt.Sprint("/lock/", t.Id) }
+ hx-target="closest .lock-row"
+ hx-confirm={ fmt.Sprint("Are you sure you want to delete lock \"", t.Name , "\"?") }
+ >Delete</a>
+ </p>
+}
+
+templ LockCreateForm(lockName string, err string) {
+ <form
+ hx-put="/lock"
+ hx-target="closest .locks-list"
+ hx-target-error="this"
+ >
+ <p>
+ <input type="text" name="lockName" value={ lockName } placeholder="Name" />
+ <input type="number" name="days" placeholder="Days" />
+ <input type="number" name="hours" placeholder="Hours" />
+ <button type="submit">Create</button>
+ </p>
+ if err != "" {
+ <p class="error">{ err }</p>
+ }
+ </form>
+}
+
+templ LocksList(locks []model.Lock, isSignedIn bool) {
+ <div class="locks-list">
+ if isSignedIn {
+ <h1>Locks</h1>
+ for _, t := range locks {
+ @lock(t)
+ }
+ <h4>Create lock</h4>
+ @LockCreateForm("", "")
+ }
+ </div>
+}
+
diff --git a/view/login.templ b/view/login.templ
index 3450e01..56e003c 100644
--- a/view/login.templ
+++ b/view/login.templ
@@ -1,7 +1,7 @@
package view
import (
- "stevenlr.com/timer/model"
+ "stevenlr.com/locker/model"
)
templ LoginFormError(currentUser *model.User, err string) {
diff --git a/view/main.templ b/view/main.templ
index 06cb872..4ae917b 100644
--- a/view/main.templ
+++ b/view/main.templ
@@ -1,14 +1,14 @@
package view
import (
- "stevenlr.com/timer/model"
+ "stevenlr.com/locker/model"
)
templ Main(contents templ.Component, currentUser *model.User) {
<!DOCTYPE html>
<html>
<head>
- <title>Cool timer app</title>
+ <title>Cool locker 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>
diff --git a/view/timer.templ b/view/timer.templ
deleted file mode 100644
index 09b1345..0000000
--- a/view/timer.templ
+++ /dev/null
@@ -1,80 +0,0 @@
-package view
-
-import (
- "fmt"
- "stevenlr.com/timer/model"
-)
-
-templ TimerTokenForm(timer model.Timer) {
- <p class="token-form">
- <button
- type="button"
- hx-post={ fmt.Sprint("/timer/", timer.Id, "/resetToken") }
- hx-target="closest .token-form"
- hx-confirm="Are you sure you want to reset the token for this timer?"
- >Reset token</button>
- <button
- type="button"
- hx-get={ fmt.Sprint("/timer/", timer.Id, "/token") }
- hx-swap="outerHTML"
- >Show token</button>
- </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>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) {
- <p><a href="/">Back to list</a></p>
- <div class="timer-info">
- @TimerInfo(timer)
- </div>
- if !timer.IsFinished() {
- <h3>Add time</h3>
- <p>
- @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>
- }
- <h3>API token</h3>
- @TimerTokenForm(timer)
-}
-
diff --git a/view/timers_list.templ b/view/timers_list.templ
deleted file mode 100644
index 69a8e53..0000000
--- a/view/timers_list.templ
+++ /dev/null
@@ -1,51 +0,0 @@
-package view
-
-import (
- "stevenlr.com/timer/model"
- "fmt"
-)
-
-templ timer(t model.Timer) {
- <p class="timer-row">
- <a href={ templ.URL(fmt.Sprint("/timer/", t.Id)) }>{ t.Name }</a>
- -
- <a
- href="javascript:void(0);"
- hx-delete={ fmt.Sprint("/timer/", t.Id) }
- hx-target="closest .timer-row"
- hx-confirm={ fmt.Sprint("Are you sure you want to delete timer \"", t.Name , "\"?") }
- >Delete</a>
- </p>
-}
-
-templ TimerCreateForm(timerName string, err string) {
- <form
- hx-put="/timer"
- hx-target="closest .timers-list"
- hx-target-error="this"
- >
- <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 != "" {
- <p class="error">{ err }</p>
- }
- </form>
-}
-
-templ TimersList(timers []model.Timer, isSignedIn bool) {
- <div class="timers-list">
- if isSignedIn {
- <h1>Timers</h1>
- for _, t := range timers {
- @timer(t)
- }
- <h4>Create timer</h4>
- @TimerCreateForm("", "")
- }
- </div>
-}
-