zaply/pages/overlay.templ

50 lines
1.8 KiB
Plaintext

package pages
import "github.com/skip2/go-qrcode"
import "encoding/base64"
templ Overlay(lnurl string) {
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>zaply</title>
<link href="/css/tailwind.css" rel="stylesheet">
<link href="/css/zap.css" rel="stylesheet">
<script src={ GetBaseUrl(ctx) + "/js/htmx.min.js" } integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
<script src={ GetBaseUrl(ctx) + "/js/htmx-sse.js" } crossorigin="anonymous"></script>
if GetEnv(ctx) == "development" {
<script src={ GetBaseUrl(ctx) + "/js/livereload.js" }></script>
}
</head>
<body>
<div hx-ext="sse" sse-connect="/overlay/sse" sse-swap="zap" hx-swap="beforeend" class="fixed bottom-0 right-0" />
<script>
document.body.addEventListener('htmx:sseMessage', function (e) {
setTimeout(() => {
const div = document.getElementById(e.detail.lastEventId)
div.classList.add('zap-animate-out')
div.addEventListener('animationend', div.remove)
}, 60_000)
})
</script>
<div class="bg-white fixed bottom-0 left-0 text-center p-3">
<img src={ "data:image/jpeg;base64," + qrEncode(lnurl) }/>
<div>scan to zap message</div>
</div>
</body>
</html>
}
func qrEncode(value string) string {
q, err := qrcode.New(value, qrcode.Medium)
q.DisableBorder = true
png, err := q.PNG(256)
if err != nil {
return ""
}
return base64.StdEncoding.EncodeToString([]byte(png))
}