home.gno
1.45 Kb · 65 lines
1package home
2
3import "chain/runtime/unsafe"
4
5// admin is the only address allowed to mutate the dashboard state.
6const admin = address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")
7
8var (
9 todos []string
10 status string
11 memeImgURL string
12)
13
14func init() {
15 todos = append(todos, "fill this todo list...")
16 status = "Online" // Initial status set to "Online"
17 memeImgURL = "https://i.imgflip.com/7ze8dc.jpg"
18}
19
20func assertIsAdmin() {
21 if unsafe.PreviousRealm().Address() != admin {
22 panic("restricted to admin")
23 }
24}
25
26func Render(path string) string {
27 content := "# Manfred's (gn)home Dashboard\n\n"
28
29 content += "## Meme\n"
30 content += "\n\n"
31
32 content += "## Status\n"
33 content += status + "\n\n"
34
35 content += "## Personal ToDo List\n"
36 for _, todo := range todos {
37 content += "- [ ] " + todo + "\n"
38 }
39 content += "\n"
40
41 // TODO: Implement a feature to list replies on r/boards on my posts
42 // TODO: Maybe integrate a calendar feature for upcoming events?
43
44 return content
45}
46
47func AddNewTodo(cur realm, todo string) {
48 assertIsAdmin()
49 todos = append(todos, todo)
50}
51
52func DeleteTodo(cur realm, todoIndex int) {
53 assertIsAdmin()
54 if todoIndex >= 0 && todoIndex < len(todos) {
55 // Remove the todo from the list by merging slices from before and after the todo
56 todos = append(todos[:todoIndex], todos[todoIndex+1:]...)
57 } else {
58 panic("Invalid todo index")
59 }
60}
61
62func UpdateStatus(cur realm, newStatus string) {
63 assertIsAdmin()
64 status = newStatus
65}