Full-width list/show pages and trim the admin table

List and show pages now use a wide container (max-w-7xl) while the form and
play pages keep the narrow column. The admin table drops Fen, Message, Notes,
Attempted and Solved — all already shown on the show page — so it fits
without right-overflow.

Closes #16
This commit is contained in:
2026-11-02 11:04:04 +01:00
parent 49c3cddffb
commit 7658450573
8 changed files with 36 additions and 32 deletions
+5 -1
View File
@@ -31,12 +31,16 @@ defmodule ChesstrainerWeb.Layouts do
default: nil, default: nil,
doc: "the current [scope](https://phoenix.hexdocs.pm/scopes.html)" doc: "the current [scope](https://phoenix.hexdocs.pm/scopes.html)"
attr :wide, :boolean,
default: false,
doc: "use a wide container instead of the default narrow column"
slot :inner_block, required: true slot :inner_block, required: true
def app(assigns) do def app(assigns) do
~H""" ~H"""
<main class="px-4 py-20 sm:px-6 lg:px-8"> <main class="px-4 py-20 sm:px-6 lg:px-8">
<div class="mx-auto max-w-2xl space-y-4"> <div class={["mx-auto space-y-4", if(@wide, do: "max-w-7xl", else: "max-w-2xl")]}>
{render_slot(@inner_block)} {render_slot(@inner_block)}
</div> </div>
</main> </main>
@@ -8,7 +8,7 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
@impl true @impl true
def render(assigns) do def render(assigns) do
~H""" ~H"""
<Layouts.app flash={@flash}> <Layouts.app flash={@flash} wide>
<.header> <.header>
Listing Endgames Listing Endgames
<:actions> <:actions>
@@ -29,39 +29,22 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
<.grouped_list :if={@groups != []} groups={@groups}> <.grouped_list :if={@groups != []} groups={@groups}>
<:header> <:header>
<tr> <tr>
<th>Fen</th>
<th>Color</th>
<th>Key</th> <th>Key</th>
<th>Rating</th> <th>Color</th>
<th>Message</th>
<th>Notes</th>
<th>Result</th> <th>Result</th>
<th>Themes</th> <th>Themes</th>
<th>Attempted</th> <th>Rating</th>
<th>Solved</th>
<th><span class="sr-only">Actions</span></th> <th><span class="sr-only">Actions</span></th>
</tr> </tr>
</:header> </:header>
<:row :let={endgame}> <:row :let={endgame}>
<tr id={"endgame-" <> endgame.id}> <tr id={"endgame-" <> endgame.id}>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.fen}
</td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.color}
</td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer"> <td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.key} {endgame.key}
</td> </td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer"> <td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.rating} {endgame.color}
</td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.message}
</td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.notes}
</td> </td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer"> <td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.result} {endgame.result}
@@ -75,10 +58,7 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
<span :if={endgame.themes == []} class="text-base-content/50">None</span> <span :if={endgame.themes == []} class="text-base-content/50">None</span>
</td> </td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer"> <td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.times_attempted} {endgame.rating}
</td>
<td phx-click={JS.navigate(~p"/admin/endgames/#{endgame}")} class="hover:cursor-pointer">
{endgame.times_solved}
</td> </td>
<td class="w-0 font-semibold"> <td class="w-0 font-semibold">
<div class="flex gap-4"> <div class="flex gap-4">
@@ -6,7 +6,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndex do
@impl true @impl true
def render(assigns) do def render(assigns) do
~H""" ~H"""
<Layouts.app flash={@flash}> <Layouts.app flash={@flash} wide>
<.header> <.header>
Endgames Endgames
<:subtitle>Pick an endgame to play.</:subtitle> <:subtitle>Pick an endgame to play.</:subtitle>
@@ -25,7 +25,7 @@ defmodule ChesstrainerWeb.EndgameLive.Show do
|> assign(:game_type, :endgame) |> assign(:game_type, :endgame)
~H""" ~H"""
<Layouts.app flash={@flash}> <Layouts.app flash={@flash} wide>
<.header> <.header>
Endgame {@endgame.id} Endgame {@endgame.id}
<:subtitle>This is a endgame record from your database.</:subtitle> <:subtitle>This is a endgame record from your database.</:subtitle>
@@ -13,7 +13,9 @@ defmodule ChesstrainerWeb.EndgameLive.FormTest do
test "creates an endgame with staged themes", %{conn: conn} do test "creates an endgame with staged themes", %{conn: conn} do
theme = theme_fixture(%{name: "Lucena"}) theme = theme_fixture(%{name: "Lucena"})
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new") {:ok, view, html} = live(conn, ~p"/admin/endgames/new")
assert html =~ "max-w-2xl"
view |> form("#theme-form", %{theme_search: "Luc"}) |> render_change() view |> form("#theme-form", %{theme_search: "Luc"}) |> render_change()
view |> element("button", "Lucena") |> render_click() view |> element("button", "Lucena") |> render_click()
@@ -11,12 +11,28 @@ defmodule ChesstrainerWeb.EndgameLive.IndexTest do
endgame_fixture() endgame_fixture()
endgame_fixture() endgame_fixture()
{:ok, view, _html} = live(conn, ~p"/admin/endgames") {:ok, view, html} = live(conn, ~p"/admin/endgames")
assert html =~ "max-w-7xl"
assert has_element?(view, "#key-group-K-v-K") assert has_element?(view, "#key-group-K-v-K")
assert has_element?(view, "#key-group-K-v-K .badge", "2") assert has_element?(view, "#key-group-K-v-K .badge", "2")
end end
test "trims the table to the key columns", %{conn: conn} do
endgame_fixture()
{:ok, view, _html} = live(conn, ~p"/admin/endgames")
view |> element("#key-group-K-v-K button") |> render_click()
for label <- ~w(Key Color Result Themes Rating) do
assert has_element?(view, "th", label)
end
for label <- ~w(Fen Message Notes Attempted Solved) do
refute has_element?(view, "th", label)
end
end
test "lazy-loads a group's endgames when expanded", %{conn: conn} do test "lazy-loads a group's endgames when expanded", %{conn: conn} do
theme = theme_fixture(%{name: "Lucena"}) theme = theme_fixture(%{name: "Lucena"})
endgame = endgame_fixture() endgame = endgame_fixture()
@@ -25,13 +41,13 @@ defmodule ChesstrainerWeb.EndgameLive.IndexTest do
{:ok, view, html} = live(conn, ~p"/admin/endgames") {:ok, view, html} = live(conn, ~p"/admin/endgames")
# collapsed: the endgame row (and its themes) are not rendered yet # collapsed: the endgame row (and its themes) are not rendered yet
refute html =~ endgame.fen refute html =~ ~p"/endgames/#{endgame}/play"
refute html =~ "Lucena" refute html =~ "Lucena"
view |> element("#key-group-K-v-K button") |> render_click() view |> element("#key-group-K-v-K button") |> render_click()
html = render(view) html = render(view)
assert html =~ endgame.fen assert html =~ ~p"/endgames/#{endgame}/play"
assert html =~ "Lucena" assert html =~ "Lucena"
end end
@@ -93,6 +93,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
assert html =~ "KQ v K" assert html =~ "KQ v K"
assert html =~ "White to move" assert html =~ "White to move"
assert html =~ "1800" assert html =~ "1800"
assert html =~ "max-w-2xl"
end end
test "raises when the endgame does not exist", %{conn: conn} do test "raises when the endgame does not exist", %{conn: conn} do
@@ -16,6 +16,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndexTest do
{:ok, view, html} = live(conn, ~p"/endgames") {:ok, view, html} = live(conn, ~p"/endgames")
assert html =~ "Endgames" assert html =~ "Endgames"
assert html =~ "max-w-7xl"
assert has_element?(view, "#key-group-K-v-K") assert has_element?(view, "#key-group-K-v-K")
refute html =~ "Lucena" refute html =~ "Lucena"