From e1f8e582b73fb7f3a7bba89e72005b24eacebb4a Mon Sep 17 00:00:00 2001 From: leohhhn Date: Wed, 18 Dec 2024 18:07:26 +0100 Subject: [PATCH] render --- examples/gno.land/r/gnoland/users/render.gno | 49 +++++++++++++------- examples/gno.land/r/gnoland/users/users.gno | 21 +++++++-- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/examples/gno.land/r/gnoland/users/render.gno b/examples/gno.land/r/gnoland/users/render.gno index 0711b4cfb80..d56b16b2436 100644 --- a/examples/gno.land/r/gnoland/users/render.gno +++ b/examples/gno.land/r/gnoland/users/render.gno @@ -1,7 +1,12 @@ package users import ( + "github.com/gnolang/gno/examples/gno.land/p/demo/avl/pager" + "github.com/gnolang/gno/examples/gno.land/p/demo/ufmt" "github.com/gnolang/gno/examples/gno.land/p/moul/realmpath" + "github.com/gnolang/gno/examples/gno.land/p/sys/users" + "github.com/gnolang/gno/examples/gno.land/r/sys/users" + "strconv" ) func Render(path string) string { @@ -10,24 +15,34 @@ func Render(path string) string { // Render home page if req.Path == "" { - // todo render home page - - //p := pager.NewPager(sys.GetUserStore(), 5) - //page := p.MustGetPageByPath(path) - // - //out += "# gno.land user registry\n" - // - //for _, item := range page.Items { - // out += ufmt.Sprintf("- User #%d: [**%s**](/r/gnoland/users:%s)\n", user.Number, user.Name, user.Name) - //} - // - //out += "\n" - //out += page.Selector() - //out += "\n\n" - //out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n" - // - //return out + p := pager.NewPager(users.GetReadonlyStore(), 5, false) + page := p.MustGetPageByPath(path) + + out += "# gno.land user registry\n" + + for _, item := range page.Items { + out += ufmt.Sprintf("- User [**%s**](/r/gnoland/users:%s)\n", item.Key, item.Key) + } + + out += "\n" + out += page.Picker() + out += "\n\n" + out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n" + + return out } + // specific user page + lookup := users.ResolveName(req.Path) + out += renderUserPage(lookup) + + return out +} + +func renderUserPage(lookup users.UserLookup) string { + // cheeck if alias + // if alias display original name as well + out := ufmt.Sprintf("# User %s\n", lookup.Name) + return out } diff --git a/examples/gno.land/r/gnoland/users/users.gno b/examples/gno.land/r/gnoland/users/users.gno index 5c961107f9e..44cc0481227 100644 --- a/examples/gno.land/r/gnoland/users/users.gno +++ b/examples/gno.land/r/gnoland/users/users.gno @@ -11,9 +11,10 @@ import ( ) const ( - reValidUsername = "^[a-z]{3}[_a-z0-9]{0,14}[0-9]{3}$" - adminAddr = "g1manfred47kzduec920z88wfr64ylksmdcedlf5" // @moul - RegisterEvent = "Register" + reValidUsername = "^[a-z]{3}[_a-z0-9]{0,14}[0-9]{3}$" + adminAddr = "g1manfred47kzduec920z88wfr64ylksmdcedlf5" // @moul + RegisterEvent = "Register" + RegisterAliasEvent = "RegisterAlias" ) var ( @@ -31,7 +32,7 @@ func Register(username string) error { std.AssertOriginCall() if Pausable.IsPaused() { - return p.ErrPaused + return pausable.ErrPaused } if matched := reUsername.MatchString(username); !matched { @@ -48,3 +49,15 @@ func Register(username string) error { std.Emit(RegisterEvent, "registrant", registrant.String(), "username", username) return nil } + +func RegisterAlias(alias string) error { + std.AssertOriginCall() + + if Pausable.IsPaused() { + return pausable.ErrPaused + } + + std.Emit(RegisterAliasEvent, "registrant", registrant.String(), "alias", alias) + + return nil +}