From fc4b31bc3c0417f0f8ca18b90aa76f0294cd3989 Mon Sep 17 00:00:00 2001
From: diamondburned
Date: Wed, 20 Mar 2024 01:06:17 -0700
Subject: [PATCH] Add submissions page
---
server/frontend/frontend.go | 4 +
server/frontend/pages/hackathon.html | 166 ++++++++++--------
.../frontend/pages/hackathon_submissions.html | 54 ++++++
.../frontend/pages/hackathon_submitted.html | 2 +-
server/frontend/styles/_hackathon.scss | 41 +++++
server/r_hackathon.go | 29 +++
6 files changed, 218 insertions(+), 78 deletions(-)
create mode 100644 server/frontend/pages/hackathon_submissions.html
diff --git a/server/frontend/frontend.go b/server/frontend/frontend.go
index 82a6588..791a9d3 100644
--- a/server/frontend/frontend.go
+++ b/server/frontend/frontend.go
@@ -24,6 +24,10 @@ type ComponentContext struct {
Username string
}
+func (c ComponentContext) IsAuthenticated() bool {
+ return c.TeamName != ""
+}
+
// Markdown is a goldmark instance.
var Markdown = goldmark.New()
diff --git a/server/frontend/pages/hackathon.html b/server/frontend/pages/hackathon.html
index e272c49..7ecc1dd 100644
--- a/server/frontend/pages/hackathon.html
+++ b/server/frontend/pages/hackathon.html
@@ -15,6 +15,8 @@ Mini Hackathon
{{ .StartTime.Format "Monday, January" }}
{{ .StartTime.Day | ordinal }}
+ at
+ {{ .StartTime.Format "3:04 PM" }}
in
{{ .Location }}
@@ -26,6 +28,10 @@ Mini Hackathon
beginners.
Move quickly, you've only got 2 hours!
+
+ There will be one grand prize for the best project as well as
+ 400 bonus points awarded to the one winner of each category.
+
@@ -62,96 +68,102 @@ Non-AI
- {{ if .IsOpen now }}
-
- Submissions are open for
-
-
+ {{ if .IsAuthenticated }}
+ {{ if .IsOpen now }}
+
+ Submissions are open for
+
+
-
+ {{ else }}
+
+
-
+ {{ end }}
{{ else }}
-
-
-
+
+ You must join or create a team to submit a project!
+
{{ end }}
diff --git a/server/frontend/pages/hackathon_submissions.html b/server/frontend/pages/hackathon_submissions.html
new file mode 100644
index 0000000..1b74f84
--- /dev/null
+++ b/server/frontend/pages/hackathon_submissions.html
@@ -0,0 +1,54 @@
+{{ template "head" }}
+{{ template "title" "Hackathon Submissions" }}
+
+{{ template "header" . }}
+
+
+
+
+
+ Hackathon Submissions
+
+
+
+
+
+ Team |
+ Category |
+ URL |
+ Description |
+
+
+
+ {{ range .Submissions }}
+
+ {{ .TeamName }} |
+
+ {{ if .Category | eq "interactive" }}
+ Interactive
+ {{ else if .Category | eq "lazy" }}
+ For the Lazy
+ {{ else if .Category | eq "otherworldly" }}
+ Otherworldly
+ {{ else if .Category | eq "non-ai" }}
+ Non-AI
+ {{ else }}
+ {{ .Category }}
+ {{ end }}
+ |
+
+
+ {{ .ProjectUrl | splitList "/" | last }}
+
+ |
+
+ {{- .ProjectDescription.String | abbrev 500 | md -}}
+ |
+
+ {{ end }}
+
+
+
+
+
+{{ template "footer" . }}
diff --git a/server/frontend/pages/hackathon_submitted.html b/server/frontend/pages/hackathon_submitted.html
index fa4ed4c..99f5870 100644
--- a/server/frontend/pages/hackathon_submitted.html
+++ b/server/frontend/pages/hackathon_submitted.html
@@ -1,5 +1,5 @@
{{ template "head" }}
-{{ template "title" "Hackathon EntrySubmitted" }}
+{{ template "title" "Hackathon Entry Submitted" }}
{{ template "header" . }}
diff --git a/server/frontend/styles/_hackathon.scss b/server/frontend/styles/_hackathon.scss
index 836da09..06421b5 100644
--- a/server/frontend/styles/_hackathon.scss
+++ b/server/frontend/styles/_hackathon.scss
@@ -65,3 +65,44 @@
}
margin-bottom: var(--spacing);
}
+
+#hackathon-submissions {
+ table {
+ th {
+ font-weight: bold;
+ color: var(--primary);
+ }
+
+ th,
+ td {
+ padding: calc(var(--spacing) / 2);
+ vertical-align: top;
+ }
+
+ @mixin ellipsize {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .team-name {
+ @include ellipsize;
+ max-width: 10em;
+ }
+
+ .project-url {
+ @include ellipsize;
+ max-width: 6em;
+ }
+
+ .project-description {
+ p {
+ margin-bottom: calc(var(--spacing) / 2);
+
+ &:last-child {
+ margin-bottom: 0;
+ }
+ }
+ }
+ }
+}
diff --git a/server/r_hackathon.go b/server/r_hackathon.go
index 8933177..1b73fb9 100644
--- a/server/r_hackathon.go
+++ b/server/r_hackathon.go
@@ -4,6 +4,7 @@ import (
"database/sql"
"net/http"
"slices"
+ "strings"
"time"
"dev.acmcsuf.com/march-madness-2024/internal/config"
@@ -14,6 +15,7 @@ import (
func (s *Server) routeHackathon(r chi.Router) {
r.Get("/", s.hackathonPage)
+ r.Get("/submissions", s.listHackathonSubmissions)
r.With(s.requireAuth).Post("/submit", s.submitHackathon)
}
@@ -86,6 +88,10 @@ func (s *Server) submitHackathon(w http.ResponseWriter, r *http.Request) {
return
}
+ if !strings.HasPrefix(submission.ProjectURL, "https://") {
+ submission.ProjectURL = "https://" + submission.ProjectURL
+ }
+
if err := s.database.SetHackathonSubmission(ctx, db.SetHackathonSubmissionParams{
TeamName: u.TeamName,
ProjectUrl: submission.ProjectURL,
@@ -104,3 +110,26 @@ func (s *Server) submitHackathon(w http.ResponseWriter, r *http.Request) {
TeamName: u.TeamName,
})
}
+
+type hackathonSubmissionsPageData struct {
+ frontend.ComponentContext
+ Submissions []db.HackathonSubmission
+}
+
+func (s *Server) listHackathonSubmissions(w http.ResponseWriter, r *http.Request) {
+ u := getAuthentication(r)
+
+ submissions, err := s.database.HackathonSubmissions(r.Context())
+ if err != nil {
+ writeError(w, http.StatusInternalServerError, err)
+ return
+ }
+
+ s.renderTemplate(w, "hackathon_submissions", hackathonSubmissionsPageData{
+ ComponentContext: frontend.ComponentContext{
+ Username: u.Username,
+ TeamName: u.TeamName,
+ },
+ Submissions: submissions,
+ })
+}