let the difficulty picker be closed

Add an X in the corner and a Cancel button, both returning home, so a user
who opens /train without wanting a session is not stuck in the modal.
This commit is contained in:
2026-11-05 15:50:17 +01:00
parent 84eee4057e
commit 1b44dae378
2 changed files with 21 additions and 4 deletions
@@ -93,10 +93,22 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
<% else %> <% else %>
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4"> <div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
<div id="difficulty-picker" class="w-full max-w-md rounded-xl bg-base-100 p-6 shadow-xl"> <div id="difficulty-picker" class="w-full max-w-md rounded-xl bg-base-100 p-6 shadow-xl">
<h2 class="text-lg font-semibold">Choose a difficulty</h2> <div class="flex items-start justify-between gap-4">
<p class="mt-1 text-sm text-muted"> <div>
Your rating: {round(@user_rating)} · bands of ±{Puzzles.band_width()} <h2 class="text-lg font-semibold">Choose a difficulty</h2>
</p> <p class="mt-1 text-sm text-muted">
Your rating: {round(@user_rating)} · bands of ±{Puzzles.band_width()}
</p>
</div>
<.link
id="close-difficulty"
navigate={~p"/"}
aria-label="Close and return home"
class="rounded-md p-1 text-muted hover:bg-base-200 hover:text-base-content focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
>
<.icon name="hero-x-mark" class="size-5" />
</.link>
</div>
<div class="mt-4 grid gap-2"> <div class="mt-4 grid gap-2">
<%= for {difficulty, label, description} <- difficulty_options(@user_rating) do %> <%= for {difficulty, label, description} <- difficulty_options(@user_rating) do %>
<.button <.button
@@ -111,6 +123,9 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
</.button> </.button>
<% end %> <% end %>
</div> </div>
<.button navigate={~p"/"} variant="ghost" class="mt-2 w-full justify-center">
Cancel
</.button>
</div> </div>
</div> </div>
<% end %> <% end %>
@@ -85,6 +85,8 @@ defmodule ChesstrainerWeb.EndgameLive.TrainTest do
assert has_element?(view, "#difficulty-easy") assert has_element?(view, "#difficulty-easy")
assert has_element?(view, "#difficulty-medium") assert has_element?(view, "#difficulty-medium")
assert has_element?(view, "#difficulty-hard") assert has_element?(view, "#difficulty-hard")
assert has_element?(view, "#close-difficulty[href='/']")
assert has_element?(view, "a", "Cancel")
assert render(view) =~ "Choose a difficulty" assert render(view) =~ "Choose a difficulty"
end end