home.gno
5.99 Kb ยท 224 lines
1package home
2
3import (
4 "chain/banker"
5 "chain/runtime"
6 "strings"
7
8 "gno.land/p/moul/md"
9 "gno.land/p/moul/txlink"
10 "gno.land/p/nt/ufmt"
11 "gno.land/r/leon/hor"
12)
13
14var (
15 pfp string
16 pfpCaption string
17 abtMe string
18
19 modernVotes int64
20 classicVotes int64
21 minimalVotes int64
22 currentTheme string
23
24 modernLink string
25 classicLink string
26 minimalLink string
27)
28
29func init() {
30 pfp = "https://avatars.githubusercontent.com/u/93043005?s=60&v=4"
31 pfpCaption = "My github profile picture"
32 abtMe = `Blockchain & Full Stack Developer and a Computer Science Student who enjoys hackathons and building cool stuff. My current passion is DeFi. Outside of work, I enjoy travelling, weightlifting and combat sports.`
33
34 modernVotes = 0
35 classicVotes = 0
36 minimalVotes = 0
37 currentTheme = "classic"
38 modernLink = txlink.NewLink("VoteModern").URL()
39 classicLink = txlink.NewLink("VoteClassic").URL()
40 minimalLink = txlink.NewLink("VoteMinimal").URL()
41 hor.Register(cross, "Matija Marijanovic's Home Realm", "")
42}
43
44func UpdatePFP(cur realm, url, caption string) {
45 if err := Auth.DoByPrevious("update_pfp", func() error {
46 pfp = url
47 pfpCaption = caption
48 return nil
49 }); err != nil {
50 panic(err)
51 }
52}
53
54func UpdateAboutMe(cur realm, col1 string) {
55 if err := Auth.DoByPrevious("update_about_me", func() error {
56 abtMe = col1
57 return nil
58 }); err != nil {
59 panic(err)
60 }
61}
62
63func VoteModern(cur realm) {
64 ugnotAmount := banker.OriginSend().AmountOf("ugnot")
65 votes := ugnotAmount
66 modernVotes += votes
67 updateCurrentTheme()
68}
69
70func VoteClassic(cur realm) {
71 ugnotAmount := banker.OriginSend().AmountOf("ugnot")
72 votes := ugnotAmount
73 classicVotes += votes
74 updateCurrentTheme()
75}
76
77func VoteMinimal(cur realm) {
78 ugnotAmount := banker.OriginSend().AmountOf("ugnot")
79 votes := ugnotAmount
80 minimalVotes += votes
81 updateCurrentTheme()
82}
83
84func CollectBalance(cur realm) {
85 if err := Auth.DoByPrevious("collect_balance", func() error {
86 banker_ := banker.NewBanker(banker.BankerTypeRealmSend)
87 ownerAddr := Address()
88 banker_.SendCoins(runtime.CurrentRealm().Address(), ownerAddr, banker_.GetCoins(runtime.CurrentRealm().Address()))
89 return nil
90 }); err != nil {
91 panic(err)
92 }
93}
94
95func Render(path string) string {
96 var sb strings.Builder
97
98 switch currentTheme {
99 case "modern":
100 // Modern theme - Clean and minimalist with emojis
101 sb.WriteString(md.H1("๐ Matija's Space"))
102 sb.WriteString(md.Image(pfpCaption, pfp))
103 sb.WriteString("\n")
104 sb.WriteString(md.Italic(pfpCaption))
105 sb.WriteString("\n")
106 sb.WriteString(md.HorizontalRule())
107 sb.WriteString(abtMe)
108 sb.WriteString("\n")
109
110 case "minimal":
111 // Minimal theme - No emojis, minimal formatting
112 sb.WriteString(md.H1("Matija Marjanovic"))
113 sb.WriteString("\n")
114 sb.WriteString(abtMe)
115 sb.WriteString("\n")
116 sb.WriteString(md.Image(pfpCaption, pfp))
117 sb.WriteString("\n")
118 sb.WriteString(pfpCaption)
119 sb.WriteString("\n")
120
121 default:
122 // Classic theme - Traditional blog style with decorative elements
123 sb.WriteString(md.H1("โจ Welcome to Matija's Homepage โจ"))
124 sb.WriteString("\n")
125 sb.WriteString(md.Image(pfpCaption, pfp))
126 sb.WriteString("\n")
127 sb.WriteString(pfpCaption)
128 sb.WriteString("\n")
129 sb.WriteString(md.HorizontalRule())
130 sb.WriteString(md.H2("About me"))
131 sb.WriteString("\n")
132 sb.WriteString(abtMe)
133 sb.WriteString("\n")
134 }
135
136 switch currentTheme {
137 case "modern":
138 sb.WriteString(md.HorizontalRule())
139 sb.WriteString(md.H2("๐จ Theme Selector"))
140 sb.WriteString("Choose your preferred viewing experience:\n")
141 items := []string{
142 md.Link(ufmt.Sprintf("Modern Design (%d votes)", modernVotes), modernLink),
143 md.Link(ufmt.Sprintf("Classic Style (%d votes)", classicVotes), classicLink),
144 md.Link(ufmt.Sprintf("Minimal Look (%d votes)", minimalVotes), minimalLink),
145 }
146 sb.WriteString(md.BulletList(items))
147
148 case "minimal":
149 sb.WriteString("\n")
150 sb.WriteString(md.H3("Theme Selection"))
151 sb.WriteString(ufmt.Sprintf("Current theme: %s\n", currentTheme))
152 sb.WriteString(ufmt.Sprintf("Votes - Modern: %d | Classic: %d | Minimal: %d\n",
153 modernVotes, classicVotes, minimalVotes))
154 sb.WriteString(md.Link("Modern", modernLink))
155 sb.WriteString(" | ")
156 sb.WriteString(md.Link("Classic", classicLink))
157 sb.WriteString(" | ")
158 sb.WriteString(md.Link("Minimal", minimalLink))
159 sb.WriteString("\n")
160
161 default:
162 sb.WriteString(md.HorizontalRule())
163 sb.WriteString(md.H2("โจ Theme Customization โจ"))
164 sb.WriteString(md.Bold("Choose Your Preferred Theme:"))
165 sb.WriteString("\n\n")
166 items := []string{
167 ufmt.Sprintf("Modern ๐ (%d votes) - %s", modernVotes, md.Link("Vote", modernLink)),
168 ufmt.Sprintf("Classic โจ (%d votes) - %s", classicVotes, md.Link("Vote", classicLink)),
169 ufmt.Sprintf("Minimal โก (%d votes) - %s", minimalVotes, md.Link("Vote", minimalLink)),
170 }
171 sb.WriteString(md.BulletList(items))
172 }
173
174 // Theme-specific footer/links section
175 switch currentTheme {
176 case "modern":
177 sb.WriteString(md.HorizontalRule())
178 sb.WriteString(md.Link("GitHub", "https://github.com/matijamarjanovic"))
179 sb.WriteString(" | ")
180 sb.WriteString(md.Link("LinkedIn", "https://www.linkedin.com/in/matijamarjanovic"))
181 sb.WriteString("\n")
182
183 case "minimal":
184 sb.WriteString("\n")
185 sb.WriteString(md.Link("GitHub", "https://github.com/matijamarjanovic"))
186 sb.WriteString(" | ")
187 sb.WriteString(md.Link("LinkedIn", "https://www.linkedin.com/in/matijamarjanovic"))
188 sb.WriteString("\n")
189
190 default:
191 sb.WriteString(md.HorizontalRule())
192 sb.WriteString(md.H3("โจ Connect With Me"))
193 items := []string{
194 md.Link("๐ GitHub", "https://github.com/matijamarjanovic"),
195 md.Link("๐ผ LinkedIn", "https://www.linkedin.com/in/matijamarjanovic"),
196 }
197 sb.WriteString(md.BulletList(items))
198 }
199
200 return sb.String()
201}
202
203func maxOfThree(a, b, c int64) int64 {
204 max := a
205 if b > max {
206 max = b
207 }
208 if c > max {
209 max = c
210 }
211 return max
212}
213
214func updateCurrentTheme() {
215 maxVotes := maxOfThree(modernVotes, classicVotes, minimalVotes)
216
217 if maxVotes == modernVotes {
218 currentTheme = "modern"
219 } else if maxVotes == classicVotes {
220 currentTheme = "classic"
221 } else {
222 currentTheme = "minimal"
223 }
224}