home.gno

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