1package home
2
3import (
4 "strconv"
5
6 "gno.land/p/demo/svg"
7 "gno.land/p/moul/debug"
8 "gno.land/p/moul/md"
9 "gno.land/p/moul/mdtable"
10 "gno.land/p/moul/txlink"
11 "gno.land/p/moul/web25"
12 "gno.land/r/leon/hof"
13 "gno.land/r/moul/config"
14)
15
16var (
17 todos []string
18 status string
19 memeImgURL string
20 web25config = web25.Config{URL: "https://moul.github.io/gno-moul-home-web25/"}
21)
22
23func init() {
24 todos = append(todos, "fill this todo list...")
25 status = "Online" // Initial status set to "Online"
26 memeImgURL = "https://i.imgflip.com/7ze8dc.jpg"
27 hof.Register()
28}
29
30func Render(path string) string {
31 content := web25config.Render(path)
32 var d debug.Debug
33
34 content += md.H1("Manfred's (gn)home Dashboard")
35
36 content += md.H2("Meme")
37 content += md.Paragraph(
38 md.Image("meme", memeImgURL),
39 )
40
41 content += md.H2("Status")
42 content += md.Paragraph(status)
43 content += md.Paragraph(md.Link("update", txlink.Call("UpdateStatus")))
44
45 d.Log("hello world!")
46
47 content += md.H2("Personal TODO List (bullet list)")
48 for i, todo := range todos {
49 idstr := strconv.Itoa(i)
50 deleteLink := md.Link("x", txlink.Call("DeleteTodo", "idx", idstr))
51 content += md.BulletItem(todo + " " + deleteLink)
52 }
53 content += md.BulletItem(md.Link("[new]", txlink.Call("AddTodo")))
54
55 content += md.H2("Personal TODO List (table)")
56 table := mdtable.Table{
57 Headers: []string{"ID", "Item", "Links"},
58 }
59 for i, todo := range todos {
60 idstr := strconv.Itoa(i)
61 deleteLink := md.Link("[del]", txlink.Call("DeleteTodo", "idx", idstr))
62 table.Append([]string{"#" + idstr, todo, deleteLink})
63 }
64 content += table.String()
65
66 content += md.H2("SVG Example")
67 content += md.Paragraph("this feature may not work with the current gnoweb version and/or configuration.")
68 content += md.Paragraph(svg.Canvas{
69 Width: 500, Height: 500,
70 Elems: []svg.Elem{
71 svg.Rectangle{50, 50, 100, 100, "red"},
72 svg.Circle{50, 50, 100, "red"},
73 svg.Text{100, 100, "hello world!", "magenta"},
74 },
75 }.String())
76
77 content += md.H2("Debug")
78 content += md.Paragraph("this feature may not work with the current gnoweb version and/or configuration.")
79 content += md.Paragraph(
80 md.Link("toggle debug", debug.ToggleURL(path)),
81 )
82
83 // TODO: my r/boards posts
84 // TODO: my r/events events
85 content += d.Render(path)
86 return content
87}
88
89func AddTodo(todo string) {
90 config.AssertIsAdmin()
91 todos = append(todos, todo)
92}
93
94func DeleteTodo(idx int) {
95 config.AssertIsAdmin()
96 if idx >= 0 && idx < len(todos) {
97 // Remove the todo from the list by merging slices from before and after the todo
98 todos = append(todos[:idx], todos[idx+1:]...)
99 } else {
100 panic("Invalid todo index")
101 }
102}
103
104func UpdateStatus(newStatus string) {
105 config.AssertIsAdmin()
106 status = newStatus
107}
home.gno
2.66 Kb ยท 107 lines