Skip to content

Commit

Permalink
render
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn committed Dec 18, 2024
1 parent e92964c commit e1f8e58
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
49 changes: 32 additions & 17 deletions examples/gno.land/r/gnoland/users/render.gno
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
21 changes: 17 additions & 4 deletions examples/gno.land/r/gnoland/users/users.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand All @@ -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
}

0 comments on commit e1f8e58

Please sign in to comment.