diff --git a/.gitignore b/.gitignore index 98c1348..58fe072 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ users.json khatru-invite .env khatru-badgern-db +db diff --git a/components.go b/components.go new file mode 100644 index 0000000..200ad86 --- /dev/null +++ b/components.go @@ -0,0 +1,47 @@ +package main + +import ( + "context" + + sdk "github.com/nbd-wtf/nostr-sdk" + . "github.com/theplant/htmlgo" +) + +func inviteTreeComponent(ctx context.Context, inviter string, loggedUser string) HTMLComponent { + children := make([]HTMLComponent, 0, len(whitelist)/2) + for pubkey, invitedBy := range whitelist { + if invitedBy == inviter { + profile := fetchAndStoreProfile(ctx, pubkey) + children = append(children, userRowComponent(ctx, profile, loggedUser)) + } + } + return Ul(children...) +} + +func userRowComponent(ctx context.Context, profile sdk.ProfileMetadata, loggedUser string) HTMLComponent { + button := Span("") + if isAncestorOf(loggedUser, profile.PubKey) && loggedUser != profile.PubKey { + button = Button("remove"). + Class(buttonClass+" px-2 bg-red-100 hover:bg-red-300"). + Attr( + "hx-post", "/remove-from-whitelist", + "hx-trigger", "click", + "hx-target", "#tree", + "hx-vals", `{"profile.pubkey": "`+profile.PubKey+`"}`, + ) + } + + return Li( + A().Href("nostr:"+profile.Npub()).Children( + Span(profile.ShortName()).Attr( + "npub", profile.Npub(), + "name", profile.ShortName(), + "_", ` +on mouseenter set my innerText to @npub then hide the next