Search Apps Documentation Source Content File Folder Download Copy Actions Download

render.gno

4.02 Kb ยท 189 lines
  1package builders
  2
  3import (
  4	"gno.land/p/jeronimoalbi/mdform"
  5	"gno.land/p/moul/md"
  6	"gno.land/p/moul/txlink"
  7)
  8
  9func renderSubmission(sub *Submission) string {
 10	out := "### " + string(sub.Applicant) + "\n\n"
 11	out += "- **Status:** " + sub.Status.String() + "\n"
 12	out += "- **Twitter:** " + sub.Twitter + "\n"
 13	out += "- **Discord:** " + sub.Discord + "\n"
 14	out += "- **GitHub:** " + sub.GitHub + "\n"
 15	out += "- **Request Type:** " + sub.RequestType + "\n"
 16	out += "- **Details:** " + sub.Details + "\n"
 17	out += "- **Submitted:** " + sub.SubmittedAt.Format("2006-01-02 15:04:05") + "\n"
 18
 19	if !sub.ReviewedAt.IsZero() {
 20		out += "- **Reviewed:** " + sub.ReviewedAt.Format("2006-01-02 15:04:05") + "\n"
 21	}
 22	if !sub.PaidAt.IsZero() {
 23		out += "- **Paid:** " + sub.PaidAt.Format("2006-01-02 15:04:05") + "\n"
 24	}
 25	if sub.ReviewNote != "" {
 26		out += "- **Note:** " + sub.ReviewNote + "\n"
 27	}
 28
 29	out += "\n"
 30	return out
 31}
 32
 33func renderAdminActions(sub *Submission) string {
 34	approveLink := txlink.NewLink("Approve").
 35		AddArgs(
 36			"addr", string(sub.Applicant),
 37			"note", "approved",
 38		).
 39		URL()
 40
 41	rejectLink := txlink.NewLink("Reject").
 42		AddArgs(
 43			"addr", string(sub.Applicant),
 44			"note", "rejected",
 45		).
 46		URL()
 47
 48	out := md.Link("โœ… Approve", approveLink) + " | " + md.Link("โŒ Reject", rejectLink)
 49
 50	if sub.Status == StatusApproved {
 51		paidLink := txlink.NewLink("MarkPaid").
 52			AddArgs(
 53				"addr", string(sub.Applicant),
 54				"note", "paid",
 55			).
 56			URL()
 57
 58		out += " | " + md.Link("๐Ÿ’ธ Mark Paid", paidLink)
 59	}
 60
 61	return out + "\n"
 62}
 63
 64func renderApplyForm() string {
 65	form := mdform.New(
 66		"exec", "Submit",
 67		"path", "/r/examples/builders",
 68	)
 69
 70	form.Input(
 71		"twitterHandle",
 72		"placeholder", "@yourhandle",
 73		"required", "true",
 74		"description", "Twitter / X handle",
 75	)
 76
 77	form.Input(
 78		"discordHandle",
 79		"placeholder", "username or username#1234",
 80		"required", "true",
 81		"description", "Discord handle",
 82	)
 83
 84	form.Input(
 85		"githubURL",
 86		"placeholder", "https://github.com/yourname",
 87		"required", "true",
 88		"description", "GitHub profile or repository URL",
 89	)
 90
 91	form.Select(
 92		"requestType",
 93		"initial",
 94		"selected", "true",
 95		"required", "true",
 96		"description", "Request type",
 97	)
 98	form.Select(
 99		"requestType",
100		"followup",
101	)
102
103	form.Textarea(
104		"applicationDetails",
105		"placeholder", "What are you building, what do you need funds for, and if this is a follow-up request, what activity should reviewers look at?",
106		"required", "true",
107		"rows", "8",
108	)
109
110	return form.String()
111}
112
113func Render(path string) string {
114	if path == "apply" {
115		out := "# Apply for Builder Faucet\n\n"
116		out += "Submit your faucet application below.\n\n"
117		out += renderApplyForm()
118		out += "\n"
119		out += md.Link("โ† Back to Registry", "/r/examples/builders") + "\n"
120		return out
121	}
122
123	if path == "admin" {
124		out := "# Admin Panel\n\n"
125		out += "**Admin:** `" + string(Admin()) + "`\n\n"
126		out += md.Link("โ† Back to Registry", "/r/examples/builders") + "\n\n"
127
128		if TotalSubmissions() == 0 {
129			out += "No submissions yet.\n"
130			return out
131		}
132
133		out += "## Review Queue\n\n"
134		for i := 0; i < TotalSubmissions(); i++ {
135			sub := SubmissionAt(i)
136			out += renderSubmission(sub)
137			out += renderAdminActions(sub)
138			out += "\n---\n\n"
139		}
140		return out
141	}
142
143	out := "# Builder Faucet Registry\n\n"
144	out += "**Total submissions:** " + itoa(TotalSubmissions()) + "\n\n"
145	out += "**Approved:** " + itoa(TotalApproved()) + "\n\n"
146	out += "**Paid:** " + itoa(TotalPaid()) + "\n\n"
147
148	out += md.Link("๐Ÿ“ Apply for Faucet", "/r/examples/builders:apply")
149	out += " | "
150	out += md.Link("๐Ÿ” Admin Panel", "/r/examples/builders:admin")
151	out += "\n\n---\n\n"
152
153	if TotalSubmissions() == 0 {
154		out += "No submissions yet.\n"
155		return out
156	}
157
158	out += "## Submissions\n\n"
159	for i := 0; i < TotalSubmissions(); i++ {
160		sub := SubmissionAt(i)
161		out += renderSubmission(sub)
162		out += "---\n\n"
163	}
164
165	return out
166}
167
168func itoa(n int) string {
169	if n == 0 {
170		return "0"
171	}
172
173	neg := false
174	if n < 0 {
175		neg = true
176		n = -n
177	}
178
179	s := ""
180	for n > 0 {
181		s = string(rune('0'+(n%10))) + s
182		n /= 10
183	}
184
185	if neg {
186		return "-" + s
187	}
188	return s
189}