Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ def index
@submissions = Submission.includes(:user, :votes).order(created_at: :desc)
end

def export
submissions = Submission.kept.includes(:user, :votes).map do |submission|
{
github_username: submission.user.github_username,
github_email: submission.user.github_email,
line1: submission.line1,
line2: submission.line2,
line3: submission.line3,
total_votes: submission.votes.size
}
end

render json: submissions
end

def toggle_discard
submission = Submission.find(params[:id])

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def create
def update
@submission = Current.user.submission

unless @submission.editable?
redirect_to root_path, alert: "Submissions can only be edited within an hour of creation."
return
end

if @submission.update(submission_params)
redirect_to root_path, notice: "Haiku updated!"
else
Expand Down
6 changes: 6 additions & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ def restore
def discarded?
discarded_at.present?
end

def editable?
return true unless persisted?

created_at > 1.hour.ago
end
end
6 changes: 3 additions & 3 deletions app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<section>
<div class="max-w-5xl mx-auto px-8">
<div class="flex-row md:flex justify-center justify-items-center gap-2 mb-10">
<div>
<div class="flex-row md:flex justify-center gap-2 mb-10">
<div class="flex justify-center">
<%= image_tag "typesense.svg", alt: "Typesense", class: "h-10" %>
</div>

<div class="text-3xl leading-tight font-medium text-[#0C2866]">
<div class="flex justify-center text-3xl leading-tight font-medium text-[#0C2866]">
Haiku Ticket Giveaway
</div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions app/views/submissions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<% end %>

<div class="space-y-4">
<div class="space-y-4 mb-4">
<div>
<%= f.label :line1, "Line 1", class: "block font-medium text-[#0C2866] mb-1" %>
<%= f.text_field :line1, class: "w-full border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#2672B5]", autofocus: true %>
Expand All @@ -34,8 +34,14 @@
<%= f.text_field :line3, class: "w-full border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#2672B5]" %>
</div>

<%= f.submit @submission.persisted? ? "Update Haiku" : "Submit Haiku", class: "bg-[#C41C1C] bg-linear-to-t from-[#C41C1C] to-[#DD423E] text-white font-medium py-3 px-6 shadow-sm rounded-sm cursor-pointer text-lg" %>
<% if @submission.editable? %>
<%= f.submit @submission.persisted? ? "Update Haiku" : "Submit Haiku", class: "bg-[#C41C1C] bg-linear-to-t from-[#C41C1C] to-[#DD423E] text-white font-medium py-3 px-6 shadow-sm rounded-sm cursor-pointer text-lg" %>
<% end %>
</div>

<p class="text-gray-500">
You can edit your haiku up to an hour after creation.
</p>
<% end %>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
end

get "admin", to: "admin#index"
get "admin/export", to: "admin#export"
post "admin/:id/toggle_discard", to: "admin#toggle_discard", as: :admin_toggle_discard

get "up" => "rails/health#show", as: :rails_health_check
Expand Down
Loading