1package hof
2
3import (
4 "strings"
5
6 "gno.land/p/demo/avl/pager"
7 "gno.land/p/demo/fqname"
8 "gno.land/p/demo/seqid"
9 "gno.land/p/demo/ufmt"
10 "gno.land/p/moul/txlink"
11)
12
13const (
14 pageSize = 5
15)
16
17func Render(path string) string {
18 out := "# Hall of Fame\n\n"
19
20 dashboardEnabled := path == "dashboard"
21
22 if dashboardEnabled {
23 out += renderDashboard()
24 }
25
26 out += exhibition.Render(path, dashboardEnabled)
27
28 return out
29}
30
31func (e Exhibition) Render(path string, dashboard bool) string {
32 out := ufmt.Sprintf("%s\n\n", e.description)
33
34 if e.items.Size() == 0 {
35 out += "No items in this exhibition currently.\n\n"
36 return out
37 }
38
39 out += "<div class='columns-2'>\n\n"
40
41 page := pager.NewPager(e.itemsSorted, pageSize, false).MustGetPageByPath(path)
42
43 for i := len(page.Items) - 1; i >= 0; i-- {
44 item := page.Items[i]
45
46 out += "<div>\n\n"
47 id, _ := seqid.FromString(item.Key)
48 out += ufmt.Sprintf("### Submission #%d\n\n", int(id))
49 out += item.Value.(*Item).Render(dashboard)
50 out += "</div>"
51 }
52
53 out += "</div><!-- /columns-2 -->\n\n"
54
55 out += page.Picker()
56
57 return out
58}
59
60func (i Item) Render(dashboard bool) string {
61 out := ufmt.Sprintf("\n```\n%s\n```\n\n", i.pkgpath)
62 out += ufmt.Sprintf("by %s\n\n", strings.Split(i.pkgpath, "/")[2])
63 out += ufmt.Sprintf("[View realm](%s)\n\n", strings.TrimPrefix(i.pkgpath, "gno.land")) // gno.land/r/leon/home > /r/leon/home
64 out += ufmt.Sprintf("Submitted at Block #%d\n\n", i.blockNum)
65
66 out += ufmt.Sprintf("#### [%d๐](%s) - [%d๐](%s)\n\n",
67 i.upvote.Size(), txlink.Call("Upvote", "pkgpath", i.pkgpath),
68 i.downvote.Size(), txlink.Call("Downvote", "pkgpath", i.pkgpath),
69 )
70
71 if dashboard {
72 out += ufmt.Sprintf("[Delete](%s)", txlink.Call("Delete", "pkgpath", i.pkgpath))
73 }
74
75 return out
76}
77
78func renderDashboard() string {
79 out := "---\n\n"
80 out += "## Dashboard\n\n"
81 out += ufmt.Sprintf("Total submissions: %d\n\n", exhibition.items.Size())
82
83 out += ufmt.Sprintf("Exhibition admin: %s\n\n", Ownable.Owner().String())
84
85 if !Pausable.IsPaused() {
86 out += ufmt.Sprintf("[Pause exhibition](%s)\n\n", txlink.Call("Pause"))
87 } else {
88 out += ufmt.Sprintf("[Unpause exhibition](%s)\n\n", txlink.Call("Unpause"))
89 }
90
91 out += "---\n\n"
92
93 return out
94}
95
96func RenderExhibWidget(itemsToRender int) string {
97 if itemsToRender < 1 {
98 return ""
99 }
100
101 out := ""
102 i := 0
103 exhibition.items.Iterate("", "", func(key string, value interface{}) bool {
104 item := value.(*Item)
105
106 out += ufmt.Sprintf("- %s\n", fqname.RenderLink(item.pkgpath, ""))
107
108 i++
109 return i >= itemsToRender
110 })
111
112 return out
113}
render.gno
2.49 Kb ยท 113 lines