From 6565b4dcf50f356a70f2698041d9e7a0654b33c4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 2 Nov 2023 10:08:33 -0300 Subject: [PATCH] nostr-sdk, eventstore, components, userRow --- .gitignore | 1 + components.go | 47 +++++++++++++++++++++++++++++++++++++++++++++ go.mod | 27 ++++++++++++++++---------- go.sum | 35 ++++++++++++++++++++-------------- handler.go | 15 ++++++++++----- main.go | 33 +++++++++++++++++++------------- nostr.go | 53 +++++++++++++++++---------------------------------- pages.go | 39 ++++++------------------------------- utils.go | 35 ---------------------------------- 9 files changed, 139 insertions(+), 146 deletions(-) create mode 100644 components.go 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