From 9da55bcde938c2b7ca7026516015633f8726b443 Mon Sep 17 00:00:00 2001 From: fungal Date: Mon, 18 Dec 2023 15:05:18 +0100 Subject: [PATCH] add requested emojis page --- main.go | 14 +++++++-- templates/index.html | 12 ++++++-- templates/requested.html | 65 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 templates/requested.html diff --git a/main.go b/main.go index ae63e60..d40c497 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,9 @@ package main import ( + "bytes" "embed" + "encoding/csv" "fmt" "html/template" "log" @@ -33,15 +35,23 @@ func handleForm(w http.ResponseWriter, r *http.Request) { } now := time.Now().UTC().Format(time.RFC3339) - entry := strings.Join([]string{now, details.Label, details.Url}, ",") - log.Print("inserting: ", entry) + entry := strings.Join([]string{now, "unknown", details.Label, details.Url}, ",") insertEntry(entry) tmpl.Execute(w, struct{ Success bool }{true}) } +func handleRequested(w http.ResponseWriter, r *http.Request) { + tmpl := template.Must(template.ParseFS(indexHTML, "templates/requested.html")) + file, _ := os.ReadFile("requests.txt") + requests, _ := csv.NewReader(bytes.NewReader(file)).ReadAll() + + tmpl.Execute(w, struct{ Requests [][]string }{requests}) +} + func setupRoutes() { http.HandleFunc("/", handleForm) + http.HandleFunc("/requested", handleRequested) http.ListenAndServe(":8080", nil) } diff --git a/templates/index.html b/templates/index.html index cd190bc..5e81a27 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,14 +10,22 @@ padding: 2rem; margin: auto; } + + nav>a { + margin: 1ch; + } +
- {{if .Success}} + {{- if .Success }}

emoji requested successfully

- {{end}} + {{- end }}

Request An Emoji

diff --git a/templates/requested.html b/templates/requested.html new file mode 100644 index 0000000..0a7635c --- /dev/null +++ b/templates/requested.html @@ -0,0 +1,65 @@ + + + + + + Emoji Request + + + + + +
+

Requested Emojis

+ + + + + + + + + + + {{- range $row := .Requests }} + + + + + + + {{- end }} + +
AtByShortcodeURL
{{index $row 0 }}{{index $row 1 }}{{index $row 2 }}{{index $row 3 }}
+
+ + + \ No newline at end of file