Skip to content

Commit

Permalink
Add submissions page
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Mar 20, 2024
1 parent a555712 commit fc4b31b
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 78 deletions.
4 changes: 4 additions & 0 deletions server/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
166 changes: 89 additions & 77 deletions server/frontend/pages/hackathon.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ <h1>Mini Hackathon</h1>
<p>
{{ .StartTime.Format "Monday, January" }}
{{ .StartTime.Day | ordinal }}
at
{{ .StartTime.Format "3:04 PM" }}
in
{{ .Location }}
</p>
Expand All @@ -26,6 +28,10 @@ <h1>Mini Hackathon</h1>
beginners.
</p>
<p><strong>Move quickly, you've only got 2 hours!</strong></p>
<p>
There will be one <mark>grand prize</mark> for the best project as well as
<mark>400 bonus points</mark> awarded to the one winner of each category.
</p>
</section>

<section class="theme">
Expand Down Expand Up @@ -62,96 +68,102 @@ <h4>Non-AI</h4>
</section>

<section>
{{ if .IsOpen now }}
<p class="countdown">
<strong>Submissions are open for</strong>
<time class="countdown-clock" datetime="{{ rfc3339 .EndTime }}">
{{ .EndTime.Sub now | formatDuration }}
</time>
</p>
{{ if .IsAuthenticated }}
{{ if .IsOpen now }}
<p class="countdown">
<strong>Submissions are open for</strong>
<time class="countdown-clock" datetime="{{ rfc3339 .EndTime }}">
{{ .EndTime.Sub now | formatDuration }}
</time>
</p>

<form id="submit-form" action="/hackathon/submit" method="post">
<label>
GitHub Repo:
<input type="text" name="project_url" value="{{ .Submission.ProjectURL }}" required />
</label>
<label>
Project Description <small>(optional)</small>:
<textarea name="project_description">{{ .Submission.ProjectDescription }}</textarea>
</label>
<label>
Category:
<form id="submit-form" action="/hackathon/submit" method="post">
<label>
<input
type="radio"
name="category"
value="interactive"
{{ if eq .Submission.Category "interactive" }}
checked
{{ end }}
/>
Interactive
GitHub Repo:
<input type="text" name="project_url" value="{{ .Submission.ProjectURL }}" required />
</label>
<label>
<input
type="radio"
name="category"
value="lazy"
{{ if eq .Submission.Category "lazy" }}
checked
{{ end }}
/>
For the lazy
Project Description <small>(optional, keep it short!)</small>:
<textarea name="project_description">{{ .Submission.ProjectDescription }}</textarea>
</label>
<label>
<input
type="radio"
name="category"
value="otherworldly"
{{ if eq .Submission.Category "otherworldly" }}
checked
{{ end }}
/>
Otherworldly
Category:
<label>
<input
type="radio"
name="category"
value="interactive"
{{ if eq .Submission.Category "interactive" }}
checked
{{ end }}
/>
Interactive
</label>
<label>
<input
type="radio"
name="category"
value="lazy"
{{ if eq .Submission.Category "lazy" }}
checked
{{ end }}
/>
For the lazy
</label>
<label>
<input
type="radio"
name="category"
value="otherworldly"
{{ if eq .Submission.Category "otherworldly" }}
checked
{{ end }}
/>
Otherworldly
</label>
<label>
<input
type="radio"
name="category"
value="non-ai"
{{ if eq .Submission.Category "non-ai" }}
checked
{{ end }}
/>
Non-AI
</label>
</label>
<label>
<input
type="radio"
name="category"
value="non-ai"
{{ if eq .Submission.Category "non-ai" }}
checked
<div class="grid" style="margin-top: var(--spacing)">
<button
type="submit"
{{ if .Submission.ProjectURL }}
class="secondary"
{{ end }}
/>
Non-AI
</label>
</label>
<div class="grid" style="margin-top: var(--spacing)">
<button
type="submit"
{{ if .Submission.ProjectURL }}
class="secondary"
>
{{ if .Submission.ProjectURL }}
Re-submit
{{ else }}
Submit
{{ end }}
</button>
</div>
</form>
{{ else }}
<div class="grid">
<button disabled class="outline">
{{ if .StartTime.After now }}
Submissions will be available once the event begins.
{{ end }}
>
{{ if .Submission.ProjectURL }}
Re-submit
{{ else }}
Submit
{{ if .EndTime.Before now }}
Submissions are closed.
{{ end }}
</button>
</div>
</form>
{{ end }}
{{ else }}
<div class="grid">
<button disabled class="outline">
{{ if .StartTime.After now }}
Submissions will be available once the event begins.
{{ end }}
{{ if .EndTime.Before now }}
Submissions are closed.
{{ end }}
</button>
</div>
<blockquote class="warn-login">
You must <a href="/join">join or create a team</a> to submit a project!
</blockquote>
{{ end }}
</section>
</article>
Expand Down
54 changes: 54 additions & 0 deletions server/frontend/pages/hackathon_submissions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{ template "head" }}
{{ template "title" "Hackathon Submissions" }}

{{ template "header" . }}


<main class="container" id="hackathon-submissions">
<article>
<header>
<h1>Hackathon Submissions</h1>
</header>

<table>
<thead>
<tr>
<th>Team</th>
<th>Category</th>
<th>URL</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{ range .Submissions }}
<tr>
<td class="team-name">{{ .TeamName }}</td>
<td class="category">
{{ 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 }}
</td>
<td class="project-url">
<a href="{{ .ProjectUrl }}" target="_blank">
{{ .ProjectUrl | splitList "/" | last }}
</a>
</td>
<td class="project-description">
{{- .ProjectDescription.String | abbrev 500 | md -}}
</td>
</tr>
{{ end }}
</tbody>
</table>
</article>
</main>

{{ template "footer" . }}
2 changes: 1 addition & 1 deletion server/frontend/pages/hackathon_submitted.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ template "head" }}
{{ template "title" "Hackathon EntrySubmitted" }}
{{ template "title" "Hackathon Entry Submitted" }}

{{ template "header" . }}

Expand Down
41 changes: 41 additions & 0 deletions server/frontend/styles/_hackathon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
29 changes: 29 additions & 0 deletions server/r_hackathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"net/http"
"slices"
"strings"
"time"

"dev.acmcsuf.com/march-madness-2024/internal/config"
Expand All @@ -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)
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
}

0 comments on commit fc4b31b

Please sign in to comment.