Skip to content

Commit

Permalink
scores: Show last updated at on every page, simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcaciuc committed Aug 16, 2024
1 parent 6fe792c commit acbcb06
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 40 deletions.
15 changes: 15 additions & 0 deletions lib/conecerto_scoreboard_web/components/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,19 @@ defmodule Conecerto.ScoreboardWeb.Layouts do

defp tab_class(true = _active), do: "border-b-2 border-red-500 text-red-500 mb-[-2px]"
defp tab_class(false = _active), do: ""

def sponsor_logos(%{sponsors: []} = assigns), do: ~H""

def sponsor_logos(assigns) do
~H"""
<div class="bg-neutral-900 text-white mt-4">
<div class="text-xl text-center font-semibold pb-2">Sponsored By</div>
<div class="flex flex-wrap justify-around bg-white my-2 p-2 gap-2">
<%= for sponsor <- @sponsors do %>
<img src={sponsor.url} class="h-[4rem] object-contain shrink-1" />
<% end %>
</div>
</div>
"""
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<div class="flex justify-center">
<div class="basis-md">
<%= @inner_content %>
<.sponsor_logos sponsors={@sponsors} />
<div class="bg-neutral-900 text-white p-1 mt-4 mb-3">
<div class="text-xl text-center font-semibold pb-2">Last Updated</div>
<div class="text-center"><%= @last_updated_at %></div>
</div>
</div>
</div>
</main>
Expand Down
73 changes: 43 additions & 30 deletions lib/conecerto_scoreboard_web/controllers/scores_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,62 @@ defmodule Conecerto.ScoreboardWeb.ScoresController do
end

def home(%{method: "GET"} = conn, _params) do
render(conn, :home,
root_font_size: @root_font_size,
active_tab: "Event",
radio_frequency: Scoreboard.config(:radio_frequency),
recent_runs: Scoreboard.list_recent_runs(10),
last_updated_at: Scoreboard.last_updated_at(),
sponsors: Brands.get_sponsors()
)
assigns =
get_assigns(
active_tab: "Event",
radio_frequency: Scoreboard.config(:radio_frequency),
recent_runs: Scoreboard.list_recent_runs(10)
)

render(conn, :home, assigns)
end

def raw(conn, _params) do
render(conn, :raw,
root_font_size: @root_font_size,
active_tab: "Raw",
raw_scores: Scoreboard.list_raw_scores(),
sponsors: Brands.get_sponsors()
)
assigns =
get_assigns(
active_tab: "Raw",
raw_scores: Scoreboard.list_raw_scores()
)

render(conn, :raw, assigns)
end

def pax(conn, _params) do
render(conn, :pax,
root_font_size: @root_font_size,
active_tab: "PAX",
pax_scores: Scoreboard.list_pax_scores(),
sponsors: Brands.get_sponsors()
)
assigns =
get_assigns(
active_tab: "PAX",
pax_scores: Scoreboard.list_pax_scores()
)

render(conn, :pax, assigns)
end

def groups(conn, _params) do
render(conn, :groups,
root_font_size: @root_font_size,
active_tab: "Groups",
groups: Scoreboard.list_all_group_scores(),
sponsors: Brands.get_sponsors()
)
assigns =
get_assigns(
active_tab: "Groups",
groups: Scoreboard.list_all_group_scores()
)

render(conn, :groups, assigns)
end

def runs(conn, _params) do
render(conn, :runs,
assigns =
get_assigns(
active_tab: "Runs",
drivers: Scoreboard.list_drivers_and_runs()
)

render(conn, :runs, assigns)
end

defp get_assigns(extra) do
[
root_font_size: @root_font_size,
active_tab: "Runs",
drivers: Scoreboard.list_drivers_and_runs(),
last_updated_at: Scoreboard.last_updated_at(),
sponsors: Brands.get_sponsors()
)
]
|> Keyword.merge(extra)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
<.scores scores={group.scores} time_column_title="PAX Best" time_column_field={:pax_time} />
</div>
<% end %>
<.sponsor_logos sponsors={@sponsors} />
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@
<div class="text-xl text-center font-semibold pb-2">Most Recent Runs</div>
<Conecerto.ScoreboardWeb.Tv.recent_runs runs={@recent_runs} />
</div>
<.sponsor_logos sponsors={@sponsors} />
<div class="bg-neutral-900 text-white p-1 mt-4 mb-3">
<div class="text-xl text-center font-semibold pb-2">Last Updated</div>
<div class="text-center"><%= @last_updated_at %></div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<div class="bg-neutral-900 text-white p-1">
<.scores scores={@pax_scores} time_column_title="PAX Best" time_column_field={:pax_time} />
</div>
<.sponsor_logos sponsors={@sponsors} />
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<div class="bg-neutral-900 text-white p-1">
<.scores scores={@raw_scores} time_column_title="Raw Best" time_column_field={:raw_time} />
</div>
<.sponsor_logos sponsors={@sponsors} />
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
</tbody>
</table>
</div>
<.sponsor_logos sponsors={@sponsors} />
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Conecerto.Scoreboard.MixProject do
def project do
[
app: :conecerto_scoreboard,
version: "0.6.0",
version: "0.7.0",
elixir: "~> 1.17",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit acbcb06

Please sign in to comment.