mirror of
https://codeberg.org/mycelium/emojiquest.git
synced 2024-11-17 14:39:14 +00:00
add requested emojis page
This commit is contained in:
parent
3ff710206f
commit
9da55bcde9
14
main.go
14
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,14 +10,22 @@
|
|||
padding: 2rem;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
nav>a {
|
||||
margin: 1ch;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav>
|
||||
<a href="/">home</a>
|
||||
<a href="/requested">requested</a>
|
||||
</nav>
|
||||
<main>
|
||||
{{if .Success}}
|
||||
{{- if .Success }}
|
||||
<h1>emoji requested successfully</h1>
|
||||
{{end}}
|
||||
{{- end }}
|
||||
<h1>Request An Emoji</h1>
|
||||
<form method="POST">
|
||||
<div>
|
||||
|
|
65
templates/requested.html
Normal file
65
templates/requested.html
Normal file
|
@ -0,0 +1,65 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Emoji Request</title>
|
||||
<style>
|
||||
main {
|
||||
max-width: 70ch;
|
||||
padding: 2rem;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
nav>a {
|
||||
margin: 1ch;
|
||||
}
|
||||
|
||||
table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
white-space: nowrap;
|
||||
border-spacing: 2ch 1ch;
|
||||
}
|
||||
|
||||
table tbody {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: start;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav>
|
||||
<a href="/">home</a>
|
||||
<a href="/requested">requested</a>
|
||||
</nav>
|
||||
<main>
|
||||
<h1>Requested Emojis</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>At</th>
|
||||
<th>By</th>
|
||||
<th>Shortcode</th>
|
||||
<th>URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{- range $row := .Requests }}
|
||||
<tr>
|
||||
<td>{{index $row 0 }}</td>
|
||||
<td>{{index $row 1 }}</td>
|
||||
<td>{{index $row 2 }}</td>
|
||||
<td>{{index $row 3 }}</td>
|
||||
</tr>
|
||||
{{- end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue