2023-10-18 11:58:09 -03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
. "github.com/theplant/htmlgo"
|
|
|
|
)
|
|
|
|
|
2023-10-28 20:21:15 -03:00
|
|
|
const buttonClass = "rounded-md bg-white p-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
|
|
|
|
2023-10-18 11:58:09 -03:00
|
|
|
func baseHTML(inside HTMLComponent) HTMLComponent {
|
2023-10-28 20:21:15 -03:00
|
|
|
navItemClass := "text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium"
|
2023-10-18 11:58:09 -03:00
|
|
|
|
|
|
|
return HTML(
|
|
|
|
Head(
|
|
|
|
Meta().Charset("utf-8"),
|
|
|
|
Meta().Name("viewport").Content("width=device-width, initial-scale=1"),
|
|
|
|
Title(s.RelayName),
|
|
|
|
Script("").Src("https://cdn.tailwindcss.com"),
|
2023-10-28 20:21:15 -03:00
|
|
|
Script("").Src("https://unpkg.com/htmx.org@1.9.6"),
|
|
|
|
Script("").Src("https://unpkg.com/hyperscript.org@0.9.12"),
|
2023-10-18 11:58:09 -03:00
|
|
|
),
|
|
|
|
Body(
|
|
|
|
Div(
|
|
|
|
H1(s.RelayName).Class("font-bold text-2xl"),
|
|
|
|
P().Text(s.RelayDescription).Class("text-lg"),
|
|
|
|
).Class("mx-auto my-6 text-center"),
|
|
|
|
Nav(
|
2023-10-28 20:21:15 -03:00
|
|
|
A().Text("information").Href("/").Class(navItemClass).Attr("hx-boost", "true", "hx-target", "main", "hx-select", "main"),
|
|
|
|
A().Text("invite tree").Href("/users").Class(navItemClass).Attr("hx-boost", "true", "hx-target", "main", "hx-select", "main"),
|
|
|
|
A().Text("reports").Href("/reports").Class(navItemClass).Attr("hx-boost", "true", "hx-target", "main", "hx-select", "main"),
|
2023-10-18 11:58:09 -03:00
|
|
|
).Class("flex flex-1 items-center justify-center"),
|
2023-10-28 20:21:15 -03:00
|
|
|
Main(inside).Class("m-4"),
|
|
|
|
).Class("mx-4 my-6"),
|
2023-10-18 11:58:09 -03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type HomePageParams struct {
|
|
|
|
RelayOwnerInfo SimpleUserInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func homePageHTML(ctx context.Context, params HomePageParams) HTMLComponent {
|
|
|
|
contact := Div()
|
|
|
|
if s.RelayContact != "" {
|
|
|
|
contact = Div().Text("alternative contact: " + s.RelayContact)
|
|
|
|
}
|
|
|
|
|
|
|
|
description := Div()
|
|
|
|
if s.RelayDescription != "" {
|
|
|
|
description = Div().Text("description: " + s.RelayDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Div(
|
|
|
|
Div().Text("name: "+s.RelayName),
|
|
|
|
description,
|
|
|
|
contact,
|
|
|
|
Div(
|
|
|
|
Text("relay master: "),
|
|
|
|
A().Text(params.RelayOwnerInfo.Name).Href("nostr:"+params.RelayOwnerInfo.Npub),
|
|
|
|
),
|
|
|
|
Br(),
|
|
|
|
Div(
|
|
|
|
Text("this relay uses"),
|
|
|
|
A().Target("_blank").Href("https://github.com/github-tijlxyz/khatru-invite").Text("Khatru Invite"),
|
|
|
|
Text(" which is built with "),
|
|
|
|
A().Target("_blank").Href("https://github.com/fiatjaf/khatru").Text("Khatru"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type InviteTreePageParams struct{}
|
|
|
|
|
|
|
|
func inviteTreePageHTML(ctx context.Context, params InviteTreePageParams) HTMLComponent {
|
2023-10-28 20:21:15 -03:00
|
|
|
return Form(
|
|
|
|
Input("pubkey").Type("text").Placeholder("npub1...").Class("w-96 rounded-md border-0 p-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600"),
|
|
|
|
Button("invite").Class(buttonClass),
|
|
|
|
Div(
|
|
|
|
buildInviteTree(ctx, s.RelayPubkey),
|
|
|
|
).Id("tree").Class("mt-3"),
|
|
|
|
).Attr("hx-post", "/add-to-whitelist", "hx-trigger", "submit", "hx-target", "#tree")
|
2023-10-18 11:58:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func buildInviteTree(ctx context.Context, invitedBy string) HTMLComponent {
|
2023-10-28 20:21:15 -03:00
|
|
|
children := make([]HTMLComponent, 0, len(whitelist))
|
2023-10-18 11:58:09 -03:00
|
|
|
for _, entry := range whitelist {
|
|
|
|
if entry.InvitedBy == invitedBy {
|
|
|
|
user := getUserInfo(ctx, entry.PublicKey)
|
2023-10-28 20:21:15 -03:00
|
|
|
children = append(children,
|
2023-10-18 11:58:09 -03:00
|
|
|
Li(
|
2023-10-28 20:21:15 -03:00
|
|
|
A().Href("nostr:"+user.Npub).Text(user.Name).Class("font-mono"),
|
|
|
|
Button("remove").Class(buttonClass).Attr("hx-post", "/remove-from-whitelist", "hx-trigger", "click", "hx-target", "#tree"),
|
2023-10-18 11:58:09 -03:00
|
|
|
buildInviteTree(ctx, entry.PublicKey),
|
2023-10-28 20:21:15 -03:00
|
|
|
).Class("ml-3"),
|
2023-10-18 11:58:09 -03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2023-10-28 20:21:15 -03:00
|
|
|
return Ul(children...)
|
2023-10-18 11:58:09 -03:00
|
|
|
}
|