Skip to content

Commit

Permalink
Rework game states structure a bit more
Browse files Browse the repository at this point in the history
I previously leaned towards adding CSS classes for spacing on
turbo_frame_tags, but the problem with that is that the original frame
tag then affects the content that it will be replaced with in the
future. So it seems that content should be up to its own styling, in all
cases. Perhaps the remaining reason to add CSS classes to turbo frames,
then, would be just to make that element, itself, behave properly / as
needed within the view. e.g. giving it a `block` class so that it
responds properly to a spacing class on its container element.
- Fixing this fixes spacing issues on Metrics - Games

Also, I previously passed up breaking out _container partials for past
User - Games and Metrics - Games. This was an oversight caused by these
views being further tucked away (out of sight out of mind). So this
commit makes structure consistent for User Games and for Metrics.

Also, fix the Game Show link from Metrics - Games to link back to the
`/metrics/games/<id>` path. i.e. we keep context on the source of the
Game Show link via Metrics pages, the same as for User Games.
- To support this, we expand the nav link for "Metrics" to make itself
  active when displaying Metrics::GamesController actions as well.
  • Loading branch information
Paul DobbinSchmaltz committed Nov 11, 2024
1 parent d860710 commit 023c3d2
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 89 deletions.
5 changes: 4 additions & 1 deletion app/views/application/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
<span class="max-sm:hidden">Sweep Ops Archive</span>
<% end %>
</li>
<li><%= active_link_to("Metrics", metrics_path) %></li>
<li>
<%= active_link_to(
"Metrics", metrics_path, includes: Metrics::GamesController.name) %>
</li>
</ul>

<%= render(
Expand Down
16 changes: 9 additions & 7 deletions app/views/games/current/_container.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
<%= render("games/current/page_nav", nav: container.nav) %>
<% end %>
<%= turbo_frame_tag(container.turbo_frame_name, class: "space-y-12") do %>
<% container.content.tap do |content| %>
<%= turbo_frame_tag(content.turbo_frame_name) do %>
<%= render("games/current/content", content:) %>
<%= turbo_frame_tag(container.turbo_frame_name) do %>
<div class="space-y-12">
<% container.content.tap do |content| %>
<%= turbo_frame_tag(content.turbo_frame_name) do %>
<%= render("games/current/content", content:) %>
<% end %>
<% end %>
<% end %>

<div class="container mx-auto">
<%= render("games/current/footer", footer: container.footer(self)) %>
<div class="container mx-auto">
<%= render("games/current/footer", footer: container.footer(self)) %>
</div>
</div>
<% end %>
14 changes: 6 additions & 8 deletions app/views/games/just_ended/_content.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<%# locals: (content:) %>
<div class="space-y-12">
<%= render("games/title", title: content.title) %>
<%= render("games/title", title: content.title) %>

<div class="space-y-6">
<%= render("games/past/status", status: content.status) %>
<%= render("games/past/board", board: content.board) %>
</div>

<%= render("games/just_ended/actions", actions: content.actions) %>
<div class="space-y-6">
<%= render("games/past/status", status: content.status) %>
<%= render("games/past/board", board: content.board) %>
</div>

<%= render("games/just_ended/actions", actions: content.actions) %>
22 changes: 22 additions & 0 deletions app/views/metrics/engagements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

# Metrics::Engagements
class Metrics::Engagements
def cache_key
[
:engagements,
Game.for_status_alliance_wins.size,
]
end

def bests_per_type = Metrics::Engagements::Bests.per_type

def display_case
DisplayCase.new
end

# Metrics::Show::Engagements::DisplayCase
class DisplayCase
include Games::Past::DisplayCaseBehaviors
end
end
13 changes: 13 additions & 0 deletions app/views/metrics/games/_container.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%# locals: (container:) %>
<%= turbo_frame_tag(container.turbo_frame_name) do %>
<div class="space-y-12">
<% cache_unless(App.debug?, container.cache_key(context: layout)) do %>
<%= render("metrics/games/content", content: container.content) %>
<% end %>

<div class="container mx-auto">
<%= render("games/past/results", results: container.results) %>
</div>
</div>
<% end %>
33 changes: 33 additions & 0 deletions app/views/metrics/games/container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# Metrics::Games::Container represents past {Game}s in the context of the
# Metrics Show page.
class Metrics::Games::Container
def initialize(game:)
@game = game
end

def game_number = game.display_id

def turbo_frame_name = Games::Past::Container.display_case_turbo_frame_name

def cache_key(context:)
[
:metrics,
game,
context.mobile? ? :mobile : :web,
]
end

def content
Metrics::Games::Content.new(game:)
end

def results
Games::Past::Results.new(game:)
end

private

attr_reader :game
end
2 changes: 1 addition & 1 deletion app/views/metrics/games/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(game:)
end

def title
Games::Title.new(game:)
Metrics::Games::Title.new(game:)
end

def board
Expand Down
12 changes: 1 addition & 11 deletions app/views/metrics/games/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<% title("Metrics -> Game ##{@view.game_number}") %>
<%= turbo_frame_tag(@view.turbo_frame_name) do %>
<div class="space-y-6">
<% cache_unless(App.debug?, @view.cache_key(context: layout)) do %>
<%= render("metrics/games/content", content: @view.content) %>
<% end %>

<div class="container mx-auto">
<%= render("games/past/results", results: @view.results) %>
</div>
</div>
<% end %>
<%= render("metrics/games/container", container: @view.container) %>
18 changes: 2 additions & 16 deletions app/views/metrics/games/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,8 @@ def initialize(game:, user:)

def game_number = game.display_id

def turbo_frame_name = Games::Past::Container.display_case_turbo_frame_name

def cache_key(context:)
[
:metrics,
game,
context.mobile? ? :mobile : :web,
]
end

def content
Metrics::Games::Content.new(game:)
end

def results
Games::Past::Results.new(game:)
def container
Metrics::Games::Container.new(game:)
end

private
Expand Down
13 changes: 13 additions & 0 deletions app/views/metrics/games/title.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# Metrics::Games::Title is a specialization on {Games::Title} that provides
# Metrics-specific {Game} paths.
class Metrics::Games::Title < Games::Title
def game_absolute_url
Router.metrics_game_url(game)
end

def game_url
Router.metrics_game_path(game)
end
end
20 changes: 1 addition & 19 deletions app/views/metrics/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@
# Metrics::Show is a View Model for displaying the Metrics Show page.
class Metrics::Show
def engagements
Engagements.new
end

# Metrics::Show::Engagements
class Engagements
def cache_key
[:engagements, Game.for_status_alliance_wins.size]
end

def bests_per_type = Metrics::Engagements::Bests.per_type

def display_case
DisplayCase.new
end

# Metrics::Show::Engagements::DisplayCase
class DisplayCase
include Games::Past::DisplayCaseBehaviors
end
Metrics::Engagements.new
end
end
13 changes: 13 additions & 0 deletions app/views/users/games/_container.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%# locals: (container:) %>
<%= turbo_frame_tag(container.turbo_frame_name) do %>
<div class="space-y-12">
<% cache_unless(App.debug?, container.cache_key(context: layout)) do %>
<%= render("users/games/content", content: container.content) %>
<% end %>

<div class="container mx-auto">
<%= render("games/past/results", results: container.results) %>
</div>
</div>
<% end %>
33 changes: 33 additions & 0 deletions app/views/users/games/container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# Users::Games::Container represents past {Game}s in the context of a
# participating player ({User}).
class Users::Games::Container
def initialize(game:, user:)
@game = game
@user = user
end

def turbo_frame_name = Games::Past::Container.display_case_turbo_frame_name

def cache_key(context:)
[
:user,
game,
context.mobile? ? :mobile : :web,
]
end

def content
Users::Games::Content.new(game:, user:)
end

def results
Games::Past::Results.new(game:)
end

private

attr_reader :game,
:user
end
10 changes: 1 addition & 9 deletions app/views/users/games/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,4 @@
<%= render("games/past/page_nav", nav: @view.nav) %>
<% end %>
<%= turbo_frame_tag(@view.turbo_frame_name, class: "space-y-12") do %>
<% cache_unless(App.debug?, @view.cache_key(context: layout)) do %>
<%= render("users/games/content", content: @view.content) %>
<% end %>

<div class="container mx-auto">
<%= render("games/past/results", results: @view.results) %>
</div>
<% end %>
<%= render("users/games/container", container: @view.container) %>
18 changes: 2 additions & 16 deletions app/views/users/games/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,8 @@ def nav
Users::Games::Nav.new(game:, user:)
end

def turbo_frame_name = Games::Past::Container.display_case_turbo_frame_name

def cache_key(context:)
[
:user,
game,
context.mobile? ? :mobile : :web,
]
end

def content
Users::Games::Content.new(game:, user:)
end

def results
Games::Past::Results.new(game:)
def container
Users::Games::Container.new(game:, user:)
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/views/users/games/title.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

# Users::Games::Title
# Users::Games::Title is a specialization on {Games::Title} that provides
# {User}-specific {Game} paths.
class Users::Games::Title < Games::Title
def initialize(game:, user:)
super(game:)
Expand Down

0 comments on commit 023c3d2

Please sign in to comment.