diff options
author | David Gay <david@davidgay.org> | 2023-11-03 02:25:06 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2023-11-03 02:25:06 -0400 |
commit | e6577d0fd5ffacd24cf52125cd44037fc33fdb9a (patch) | |
tree | cc723b8a01df75735b01bd69c4ca3b32ea2082c5 /app | |
parent | d4c92922e393876e93ad13943ba45fb08586e6c8 (diff) |
Better home#index, using partials
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/home_controller.rb | 3 | ||||
-rw-r--r-- | app/views/checkpoints/_checkpoint.html.erb | 35 | ||||
-rw-r--r-- | app/views/home/index.html.erb | 31 | ||||
-rw-r--r-- | app/views/pokedex_entries/_entry.html.erb | 12 | ||||
-rw-r--r-- | app/views/pokedex_entries/index.html.erb | 13 | ||||
-rw-r--r-- | app/views/runs/show.html.erb | 36 |
6 files changed, 68 insertions, 62 deletions
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 59cac59..6e38c41 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,6 +2,7 @@ class HomeController < ApplicationController skip_before_action :authenticate_user! def index - @latest_checkpoints = Checkpoint.last(5).sort_by(&:created_at).reverse + @latest_checkpoints = Checkpoint.order(:created_at).last(8).reverse + @latest_entries = PokedexEntry.order(:created_at).last(8).reverse end end diff --git a/app/views/checkpoints/_checkpoint.html.erb b/app/views/checkpoints/_checkpoint.html.erb new file mode 100644 index 0000000..a8d70d8 --- /dev/null +++ b/app/views/checkpoints/_checkpoint.html.erb @@ -0,0 +1,35 @@ +<div class="border-l border-orange-900 p-2"> + <div class="flex flex-col"> + <div class="flex space-x-2 text-sm"> + <div> + <% case checkpoint.kind.to_sym %> + <% when :comment %> + 💬 + <% when :checkin %> + 📬 + <% when :checkout %> + 📠+ <% else %> + <%# Should never happen. %> + <% end %> + </div> + <div class="flex space-x-2"> + <span class="uppercase"><%= checkpoint.kind %></span> + <% if checkpoint.save_file.attached? %> + <%= link_to "Download save file", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> + <% end %> + </div> + + </div> + <div> + </div> + <div class="text-sm"> + <%= time_ago_in_words(checkpoint.created_at) %> ago by + <%= link_to checkpoint.user.name || "???", user_path(checkpoint.user) %> + <span>@ <%= checkpoint.created_at %></span> + </div> + <% if checkpoint.comment %> + <div class="text-lg"><%= checkpoint.comment %></div> + <% end %> + </div> +</div> diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index a961565..fe9031e 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,24 +1,27 @@ <div class="space-y-8"> <h1 class="font-bold text-2xl">Welcome to the Cable Club!</h1> - <div class="grid grid-cols-2"> - <div class="space-y-4"> + <div class="grid grid-cols-1 md:grid-cols-3"> + <div class="space-y-2"> <h2>Latest checkpoints</h2> - <ul class="list-disc"> + <div class="space-y-2"> <% @latest_checkpoints.each do |checkpoint| %> - <li>At <%= checkpoint.created_at %> - <%= checkpoint.user.name %> checked in a save for - <%= link_to checkpoint.run.title, run_path(checkpoint.run) %> (<%= checkpoint.run.game.title %>) - <% if checkpoint.save_file.attached? %> - <%= link_to "[save file]", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> - <% end %> - </li> + <%= render partial: "checkpoints/checkpoint", locals: {checkpoint:} %> <% end %> - </ul> + </div> </div> - <div class="flex justify-around"> - <%= image_tag "pokemon_classic_watercolor_small.png" %> + + <div class="space-y-2"> + <h2>Latest Pokédex entries</h2> + <div class="space-y-2"> + <% @latest_entries.each do |entry| %> + <%= render partial: "pokedex_entries/entry", locals: {entry:} %> + <% end %> + </div> </div> - </div> + <div> + <%= image_tag "pokemon_classic_watercolor_small.png", class: "mx-auto" %> + </div> + </div> </div> diff --git a/app/views/pokedex_entries/_entry.html.erb b/app/views/pokedex_entries/_entry.html.erb new file mode 100644 index 0000000..992aa69 --- /dev/null +++ b/app/views/pokedex_entries/_entry.html.erb @@ -0,0 +1,12 @@ +<div class="flex space-x-2 items-center"> + <div class="flex justify-around bg-white h-[60px] w-[60px] border border-orange-900 + p-1 rounded shadow"> + <%= image_tag entry.pokemon.sprite_path(shiny: entry.shiny?) %> + </div> + <div> + <div><%= "Shiny " if entry.shiny? %><%= entry.pokemon.name %></div> + <div class="text-sm">Recorded by + <%= link_to entry.user.name || "???", user_path(entry.user) %> @ <%= entry.recorded_at %> + </div> + </div> +</div> diff --git a/app/views/pokedex_entries/index.html.erb b/app/views/pokedex_entries/index.html.erb index e31cf2d..d5bdfb1 100644 --- a/app/views/pokedex_entries/index.html.erb +++ b/app/views/pokedex_entries/index.html.erb @@ -3,18 +3,7 @@ <div class="space-y-2 p-4 h-[400px] border border-orange-900 overflow-y-scroll"> <% @pokedex_entries.each do |entry| %> - <div class="flex space-x-2 items-center"> - <div class="flex justify-around bg-white h-[60px] w-[60px] border border-orange-900 - rounded shadow"> - <%= image_tag entry.pokemon.sprite_path(shiny: entry.shiny?) %> - </div> - <div> - <div><%= "Shiny " if entry.shiny? %><%= entry.pokemon.name %></div> - <div class="text-sm">Recorded by - <%= link_to entry.user.name || "???", user_path(entry.user) %> @ <%= entry.recorded_at %> - </div> - </div> - </div> + <%= render partial: "entry", locals: {entry:} %> <% end %> </div> <% end %> diff --git a/app/views/runs/show.html.erb b/app/views/runs/show.html.erb index cca5029..9db4f53 100644 --- a/app/views/runs/show.html.erb +++ b/app/views/runs/show.html.erb @@ -27,41 +27,7 @@ <div><%= link_to "New checkpoint", new_run_checkpoint_path(@run) %></div> <% @run.checkpoints.order(:created_at).reverse.each do |checkpoint| %> - <div class="border-l border-orange-900 p-2"> - <div class="flex flex-col"> - <div class="flex space-x-2 text-sm"> - <div> - <% case checkpoint.kind.to_sym %> - <% when :comment %> - 💬 - <% when :checkin %> - 📬 - <% when :checkout %> - 📠- <% else %> - <%# Should never happen. %> - <% end %> - </div> - <div class="flex space-x-2"> - <span class="uppercase"><%= checkpoint.kind %></span> - <% if checkpoint.save_file.attached? %> - <%= link_to "Download save file", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> - <% end %> - </div> - - </div> - <div> - </div> - <div class="text-sm"> - <%= time_ago_in_words(checkpoint.created_at) %> ago by - <%= link_to checkpoint.user.name || "???", user_path(checkpoint.user) %> - <span>@ <%= checkpoint.created_at %></span> - </div> - <% if checkpoint.comment %> - <div class="text-lg"><%= checkpoint.comment %></div> - <% end %> - </div> - </div> + <%= render partial: "checkpoints/checkpoint", locals: {checkpoint:} %> <% end %> </div> <div> |