102 lines
3.3 KiB
Plaintext
Raw Normal View History

2024-07-14 12:57:40 +02:00
package pages
import (
2024-09-11 12:21:58 +02:00
"fmt"
2024-07-14 12:57:40 +02:00
"git.ekzyis.com/ekzyis/delphi.market/server/router/pages/components"
"git.ekzyis.com/ekzyis/delphi.market/types"
"strconv"
"time"
)
2024-09-11 12:21:58 +02:00
templ User(user *types.User, errors *types.UserEditError) {
2024-07-14 12:57:40 +02:00
<html>
@components.Head()
<body class="container">
@components.Nav()
<div id="content" class="flex flex-col">
@components.Figlet("random", "user")
<div
2024-09-27 07:18:42 +02:00
class="grid grid-cols-[1fr_3fr_1fr] gap-4 my-3 mx-auto"
2024-07-14 12:57:40 +02:00
hx-target="#content"
hx-swap="outerHTML"
hx-select="#content"
hx-push-url="true"
hx-select-oob="#nav"
>
<div class="font-bold">id</div>
<div>{ strconv.Itoa(user.Id) }</div>
2024-09-27 07:18:42 +02:00
<div class="font-bold col-start-1">name</div>
2024-09-11 12:21:58 +02:00
<div>
<div class="flex">
2024-09-27 07:18:42 +02:00
<span id="name" class={ maybeShow("w-40", errors == nil || errors.Name == "") }>{ user.Name }</span>
2024-09-11 12:21:58 +02:00
<form
2024-09-27 07:18:42 +02:00
id="name-form"
2024-09-11 12:21:58 +02:00
class="hidden flex mb-0"
hx-put="/user"
hx-push-url="false"
hx-target="#name"
hx-select="#name"
2024-09-27 07:18:42 +02:00
hx-select-oob="#name-error"
2024-09-11 12:21:58 +02:00
>
<input
name="name"
type="text"
value={ user.Name }
2024-09-27 07:18:42 +02:00
class="w-40 font-mono"
2024-09-11 12:21:58 +02:00
/>
</form>
</div>
if errors != nil && errors.Name != "" {
2024-09-27 07:18:42 +02:00
<div id="name-error" class="w-40 text-xs text-error py-1">{ errors.Name }</div>
2024-09-11 12:21:58 +02:00
} else {
2024-09-27 07:18:42 +02:00
<div id="name-error" class="hidden"></div>
2024-09-11 12:21:58 +02:00
}
2024-09-11 11:17:28 +02:00
</div>
2024-09-27 07:18:42 +02:00
<div id="name-btns" class="grid grid-cols-2 w-[90px] h-min self-center">
<button id="name-save" form="name-form" class="h-min hidden px-3 text-xs self-center" type="submit">save</button>
<button id="name-cancel" class="h-min hidden text-muted hover:text-reset self-center text-xs ms-2">cancel</button>
<button id="name-edit" class="col-span-2 text-muted hover:text-reset text-xs">edit</button>
</div>
2024-07-14 12:57:40 +02:00
<div class="font-bold">joined</div>
<div>{ user.CreatedAt.Format(time.DateOnly) }</div>
2024-09-27 07:18:42 +02:00
<div class="font-bold col-start-1">sats</div>
2024-09-09 00:35:01 +02:00
<!-- TODO: implement withdrawal of sats -->
2024-09-27 07:18:42 +02:00
<div>{ strconv.Itoa(int(user.Msats) / 1000) }</div>
<button class="text-muted hover:text-reset text-xs self-center h-min">withdraw</button>
2024-09-09 00:35:01 +02:00
<!-- TODO: add WebLN and NWC for send+recv -->
2024-09-27 07:18:42 +02:00
<button hx-post="/logout" class="col-start-2">logout</button>
2024-07-14 12:57:40 +02:00
</div>
2024-09-11 11:17:28 +02:00
<script>
function toggleForm () {
htmx.toggleClass("#name", "hidden")
2024-09-27 07:18:42 +02:00
htmx.toggleClass("#name-form", "hidden")
htmx.toggleClass("#name-save", "hidden")
htmx.toggleClass("#name-cancel", "hidden")
htmx.toggleClass("#name-edit", "hidden")
// make sure buttons don't shift on error
htmx.toggleClass("#name-btns", "self-center")
// reset error message on toggle
htmx.addClass("#name-error", "hidden")
$("#name-form>input").focus()
2024-09-11 11:17:28 +02:00
}
2024-09-27 07:18:42 +02:00
htmx.on("#name-edit", "click", toggleForm)
htmx.on("#name-cancel", "click", toggleForm)
htmx.on("#name-form", "htmx:afterRequest", ({ detail }) => {
// only toggle form if request was successful
2024-09-11 12:21:58 +02:00
if (detail.successful) toggleForm()
})
2024-09-11 11:17:28 +02:00
</script>
2024-07-14 12:57:40 +02:00
</div>
@components.Footer()
</body>
</html>
}
2024-09-11 12:21:58 +02:00
func maybeShow(class string, show bool) string {
if show {
return class
}
return fmt.Sprintf("%s %s", class, "hidden")
}