Skip to content

Commit

Permalink
fix: anchors + misc
Browse files Browse the repository at this point in the history
Signed-off-by: Norman <[email protected]>
  • Loading branch information
n0izn0iz committed Jan 2, 2025
1 parent 892014b commit 01cd8b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
2 changes: 0 additions & 2 deletions examples/gno.land/r/demo/payrolls/payrolls.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"gno.land/p/demo/ufmt"
)

// TODO: support grc20

type DistribFn func(elapsed time.Duration) uint64
type BreakupFn func(elapsed time.Duration, pauseDuration time.Duration, source BreakupSource) int64

Expand Down
47 changes: 34 additions & 13 deletions examples/gno.land/r/demo/payrolls/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
rusers "gno.land/r/demo/users"
)

// TODO: pagination
const listMaxSize = 50

func Render(renderPath string) string {
Expand Down Expand Up @@ -47,9 +46,14 @@ func Render(renderPath string) string {
estimatedAvailable := uint64(0)
estimatedClaimable := uint64(0)
shouldEstimate := tree.Size() <= listMaxSize
if shouldEstimate {
sb.WriteString("## All payrolls\n")
} else {
sb.WriteString("## Latest payrolls\n")
}
tree.ReverseIterateByOffset(0, listMaxSize, func(key string, value interface{}) bool {
p := value.(*payroll)
sb.WriteString(p.render("beneficiary"))
sb.WriteString(renderPayroll(p, "beneficiary"))

if shouldEstimate {
available := p.available()
Expand Down Expand Up @@ -117,13 +121,18 @@ func Render(renderPath string) string {
tree = avl.NewTree()
}
shouldEstimate := tree.Size() <= listMaxSize
if shouldEstimate {
payrollsBuffer.WriteString("## All payrolls\n")
} else {
payrollsBuffer.WriteString("## Latest payrolls\n")
}
tree.ReverseIterateByOffset(0, listMaxSize, func(key string, value interface{}) bool {
p := value.(*payroll)
if shouldEstimate {
estimatedDebt += p.available()
estimatedDay += p.estimateDay()
}
payrollsBuffer.WriteString(p.render("vault"))
payrollsBuffer.WriteString(renderPayroll(p, "vault"))
return false
})

Expand Down Expand Up @@ -174,14 +183,16 @@ func Render(renderPath string) string {
w.WriteString(payrollsBuffer.String())

case strings.HasPrefix(renderPath, "/d/"):
w.WriteString("# Payroll details\n")

idStr := strings.TrimPrefix(renderPath, "/d/")

w.WriteString(ufmt.Sprintf("# Payroll #%s\n", idStr))

p, ok := payrolls.Get(idStr)
if !ok {
return ufmt.Sprintf("❓ Payroll %q not found", idStr)
}
w.WriteString(p.(*payroll).render(""))

w.WriteString(renderPayroll(p.(*payroll), "details"))

case renderPath == "":
w.WriteString("# Payrolls\n")
Expand All @@ -193,21 +204,27 @@ func Render(renderPath string) string {
}))
w.WriteString(renderActions("", actions))

if payrolls.Size() <= listMaxSize {
w.WriteString("## All payrolls\n")
} else {
w.WriteString("## Latest payrolls\n")
}
payrolls.ReverseIterateByOffset(0, listMaxSize, func(key string, value interface{}) bool {
w.WriteString(value.(*payroll).render(""))
w.WriteString(renderPayroll(value.(*payroll), "home"))
return false
})

w.WriteString("\n\nTODO\n")
w.WriteString("- [ ] Fix anchors\n")
w.WriteString("## TODO\n")
w.WriteString("- [ ] Show created at\n")
w.WriteString("- [ ] Show running duration\n")
w.WriteString("- [ ] Support any coin\n")
w.WriteString("- [ ] Render breakup amount\n")
w.WriteString("- [ ] Unit tests\n")
w.WriteString("- [ ] txtar\n")
w.WriteString("- [ ] Write doc\n")

w.WriteString("\n\nv2\n\n")
w.WriteString("## v2\n")
w.WriteString("- [ ] Gnoweb pagination\n")
w.WriteString("- [ ] Archive\n")
w.WriteString("- [ ] Details: Events history\n")
w.WriteString("- [ ] PoV Tags\n")
Expand All @@ -222,10 +239,12 @@ func Render(renderPath string) string {
return w.String()
}

func (p *payroll) render(pov string) string {
func renderPayroll(p *payroll, pov string) string {
sb := strings.Builder{}

sb.WriteString(ufmt.Sprintf("### [%s](%s:/d/%s)\n", p.id.String(), linkPrefix(), p.id.String()))
if pov != "details" {
sb.WriteString(ufmt.Sprintf("### %s\n", p.id.String()))
}

sb.WriteString(ufmt.Sprintf(" - ✍️ Label: %s\n", p.label))

Expand Down Expand Up @@ -280,7 +299,9 @@ func (p *payroll) render(pov string) string {
sb.WriteString(ufmt.Sprintf(" - 🛑 Stopped since: %s\n", p.stoppedAt.Format(time.DateTime)))
}

// TODO: render breakup amount, we need to be explicit depending on source
if pov != "details" {
sb.WriteString(ufmt.Sprintf(" - 🔍 [Details](%s:/d/%s)\n", linkPrefix(), p.id.String()))
}

actions := []string{}

Expand Down

0 comments on commit 01cd8b6

Please sign in to comment.