From e6577d0fd5ffacd24cf52125cd44037fc33fdb9a Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 3 Nov 2023 02:25:06 -0400 Subject: Better home#index, using partials --- app/controllers/home_controller.rb | 3 ++- app/views/checkpoints/_checkpoint.html.erb | 35 +++++++++++++++++++++++++++++ app/views/home/index.html.erb | 31 +++++++++++++------------ app/views/pokedex_entries/_entry.html.erb | 12 ++++++++++ app/views/pokedex_entries/index.html.erb | 13 +---------- app/views/runs/show.html.erb | 36 +----------------------------- 6 files changed, 68 insertions(+), 62 deletions(-) create mode 100644 app/views/checkpoints/_checkpoint.html.erb create mode 100644 app/views/pokedex_entries/_entry.html.erb 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 @@ +
+
+
+
+ <% case checkpoint.kind.to_sym %> + <% when :comment %> + 💬 + <% when :checkin %> + 📬 + <% when :checkout %> + 📭 + <% else %> + <%# Should never happen. %> + <% end %> +
+
+ <%= checkpoint.kind %> + <% if checkpoint.save_file.attached? %> + <%= link_to "Download save file", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> + <% end %> +
+ +
+
+
+
+ <%= time_ago_in_words(checkpoint.created_at) %> ago by + <%= link_to checkpoint.user.name || "???", user_path(checkpoint.user) %> + @ <%= checkpoint.created_at %> +
+ <% if checkpoint.comment %> +
<%= checkpoint.comment %>
+ <% end %> +
+
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 @@

Welcome to the Cable Club!

-
-
+
+

Latest checkpoints

-
    +
    <% @latest_checkpoints.each do |checkpoint| %> -
  • 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 %> -
  • + <%= render partial: "checkpoints/checkpoint", locals: {checkpoint:} %> <% end %> -
+
-
- <%= image_tag "pokemon_classic_watercolor_small.png" %> + +
+

Latest Pokédex entries

+
+ <% @latest_entries.each do |entry| %> + <%= render partial: "pokedex_entries/entry", locals: {entry:} %> + <% end %> +
-
+
+ <%= image_tag "pokemon_classic_watercolor_small.png", class: "mx-auto" %> +
+
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 @@ +
+
+ <%= image_tag entry.pokemon.sprite_path(shiny: entry.shiny?) %> +
+
+
<%= "Shiny " if entry.shiny? %><%= entry.pokemon.name %>
+
Recorded by + <%= link_to entry.user.name || "???", user_path(entry.user) %> @ <%= entry.recorded_at %> +
+
+
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 @@
<% @pokedex_entries.each do |entry| %> -
-
- <%= image_tag entry.pokemon.sprite_path(shiny: entry.shiny?) %> -
-
-
<%= "Shiny " if entry.shiny? %><%= entry.pokemon.name %>
-
Recorded by - <%= link_to entry.user.name || "???", user_path(entry.user) %> @ <%= entry.recorded_at %> -
-
-
+ <%= render partial: "entry", locals: {entry:} %> <% end %>
<% 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 @@
<%= link_to "New checkpoint", new_run_checkpoint_path(@run) %>
<% @run.checkpoints.order(:created_at).reverse.each do |checkpoint| %> -
-
-
-
- <% case checkpoint.kind.to_sym %> - <% when :comment %> - 💬 - <% when :checkin %> - 📬 - <% when :checkout %> - 📭 - <% else %> - <%# Should never happen. %> - <% end %> -
-
- <%= checkpoint.kind %> - <% if checkpoint.save_file.attached? %> - <%= link_to "Download save file", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> - <% end %> -
- -
-
-
-
- <%= time_ago_in_words(checkpoint.created_at) %> ago by - <%= link_to checkpoint.user.name || "???", user_path(checkpoint.user) %> - @ <%= checkpoint.created_at %> -
- <% if checkpoint.comment %> -
<%= checkpoint.comment %>
- <% end %> -
-
+ <%= render partial: "checkpoints/checkpoint", locals: {checkpoint:} %> <% end %>
-- cgit v1.2.3