2023-10-18 11:58:09 -03:00
package main
import (
"context"
2023-11-02 10:08:33 -03:00
sdk "github.com/nbd-wtf/nostr-sdk"
2023-10-18 11:58:09 -03:00
. "github.com/theplant/htmlgo"
)
2023-10-28 21:40:54 -03:00
const buttonClass = "rounded-md text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300"
2023-10-28 20:21:15 -03:00
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-11-02 10:08:33 -03:00
A ( ) . Text ( "login" ) . Href ( "#" ) . Class ( navItemClass ) .
Attr ( "_" , "on click get window.nostr.signEvent({created_at: Math.round(Date.now()/1000), kind: 27235, tags: [['domain', " + s . Domain + "]], content: ''}) then get JSON.stringify(it) then set cookies['nip98'] to it" ) ,
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 {
2023-11-02 10:08:33 -03:00
RelayOwnerInfo sdk . ProfileMetadata
2023-10-18 11:58:09 -03:00
}
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: " ) ,
2023-11-02 10:08:33 -03:00
A ( ) . Text ( params . RelayOwnerInfo . Name ) . Href ( "nostr:" + params . RelayOwnerInfo . Npub ( ) ) ,
2023-10-18 11:58:09 -03:00
) ,
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" ) ,
) ,
)
}
2023-10-28 21:40:54 -03:00
type InviteTreePageParams struct {
LoggedUser string
}
2023-10-18 11:58:09 -03:00
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" ) ,
2023-10-28 21:40:54 -03:00
Button ( "invite" ) . Class ( buttonClass + " p-2 bg-white hover:bg-gray-50" ) ,
2023-10-28 20:21:15 -03:00
Div (
2023-11-02 10:08:33 -03:00
inviteTreeComponent ( ctx , "" , params . LoggedUser ) ,
2023-10-28 20:21:15 -03:00
) . Id ( "tree" ) . Class ( "mt-3" ) ,
2023-10-29 13:45:46 -03:00
) . Attr (
"hx-post" , "/add-to-whitelist" ,
"hx-trigger" , "submit" ,
"hx-target" , "#tree" ,
"_" , "on htmx:afterRequest(elt, successful) if successful and elt is I call I.reset()" ,
)
2023-10-18 11:58:09 -03:00
}