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