landing page (#63)

* remove daisyui and rebuild styles

* very basic setup of new design - missing components etc

* basic navbar with reusable landing components

* basic puzzle of the day

* update todos

* update todos

* add curated landing puzzle cards with selectable board (#55)

* update with footer

* add button to solve today's puzzle

* Make landing page a dead view

Render the home page from PageController with a static board preview, link puzzle cards and CTAs to public-code play routes, count puzzles from the DB, and add a global footer.

* Serve a marketing-only JS bundle on the landing page

Build a small marketing entry point with phoenix_html and the plain-DOM navbar, select it on controller-rendered pages, and keep the full LiveView bundle for LiveView pages.

* Add landing page SEO metadata

Replace the Phoenix default title with a descriptive Lucid Chess title, and add description, canonical, Open Graph, and Twitter card tags to the landing page.

* Complete the hero copy block

Add the spark icon primitive and the Endgames, made clear eyebrow. The primary CTA keeps linking to the active puzzle rather than scrolling to the board.

* Add a persisted global daily puzzle

Assign one endgame per UTC day in a daily_puzzles table with a unique date, preferring endgames unused in the last 30 days and falling back to any. Concurrent first requests insert with on-conflict-ignore and read the winning row. The landing board now shows the daily puzzle.

* remove unused CSS, nav links, time pill

* allow devices to connect to dev server by changing IP address to 0.0.0.0

* Restore the colour-mode switch and add a dark palette

* Use brand colour tokens on the play page

* self host fonts  - closes issue #62

* begin splitting CSS into modules

* remove hover on hero chessboard, split more css modules

* remove interactivity from hero chessboard

* update todo
This commit is contained in:
2026-11-05 13:52:14 +01:00
committed by GitHub
parent fd6277ef92
commit 93806b9ab2
60 changed files with 2253 additions and 11028 deletions
@@ -8,12 +8,10 @@ defmodule ChesstrainerWeb.CoreComponents do
with doc strings and declarative assigns. You may customize and style
them in any way you want, based on your application growth and needs.
The foundation for styling is Tailwind CSS, a utility-first CSS framework,
augmented with daisyUI, a Tailwind CSS plugin that provides UI components
and themes. Here are useful references:
* [daisyUI](https://daisyui.com/docs/intro/) - a good place to get
started and see the available components.
The foundation for styling is Tailwind CSS, a utility-first CSS framework.
Semantic colors such as `base-100`, `base-content` and `primary` are defined
in `assets/css/app.css` and switch with the `data-theme` attribute. Here are
useful references:
* [Tailwind CSS](https://tailwindcss.com) - the foundational framework
we build on. You will use it for layout, sizing, flexbox, grid, and
@@ -31,6 +29,24 @@ defmodule ChesstrainerWeb.CoreComponents do
alias Phoenix.LiveView.JS
@input_class "w-full rounded-md border border-base-300 bg-base-100 px-3 py-2 text-sm text-base-content placeholder:text-base-content/50 focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/30"
@input_error_class "border-error focus:border-error focus:ring-error/30"
@label_class "mb-1 block text-sm font-medium text-base-content"
@checkbox_class "size-4 rounded border-base-300 accent-primary"
defp input_class, do: @input_class
defp input_error_class, do: @input_error_class
defp label_class, do: @label_class
defp checkbox_class, do: @checkbox_class
@table_class "w-full border-collapse text-left text-sm [&_th]:border-b [&_th]:border-base-200 [&_th]:px-4 [&_th]:py-3 [&_th]:font-semibold [&_td]:border-b [&_td]:border-base-200 [&_td]:px-4 [&_td]:py-3 [&_tbody_tr:nth-child(odd)]:bg-base-200/50"
@doc """
Returns the shared data-table classes, for tables that render their own
`<thead>`/`<tbody>` markup.
"""
def table_class, do: @table_class
@doc """
Renders flash notices.
@@ -63,13 +79,13 @@ defmodule ChesstrainerWeb.CoreComponents do
id={@id}
phx-click={JS.push("lv:clear-flash", value: %{key: @kind}) |> hide("##{@id}")}
role="alert"
class="toast toast-top toast-end z-50"
class="fixed right-4 top-4 z-50 flex flex-col gap-2"
{@rest}
>
<div class={[
"alert w-80 sm:w-96 max-w-80 sm:max-w-96 text-wrap",
@kind == :info && "alert-info",
@kind == :error && "alert-error"
"flex w-80 max-w-80 items-start gap-3 rounded-lg border px-4 py-3 text-sm text-wrap shadow-lg sm:w-96 sm:max-w-96",
@kind == :info && "border-info bg-info text-info-content",
@kind == :error && "border-error bg-error text-error-content"
]}>
<.icon :if={@kind == :info} name="hero-information-circle" class="size-5 shrink-0" />
<.icon :if={@kind == :error} name="hero-exclamation-circle" class="size-5 shrink-0" />
@@ -97,16 +113,24 @@ defmodule ChesstrainerWeb.CoreComponents do
"""
attr :rest, :global, include: ~w(href navigate patch method download name value disabled)
attr :class, :any
attr :variant, :string, values: ~w(primary)
attr :variant, :string, values: ~w(primary secondary ghost danger)
slot :inner_block, required: true
def button(%{rest: rest} = assigns) do
variants = %{"primary" => "btn-primary", nil => "btn-primary btn-soft"}
variants = %{
"primary" => "bg-primary text-primary-content hover:bg-primary/90",
"secondary" => "border border-base-300 bg-base-100 text-base-content hover:bg-base-200",
"ghost" => "text-base-content hover:bg-base-200",
"danger" => "bg-error text-error-content hover:bg-error/90",
nil => "bg-primary/15 text-primary hover:bg-primary/25"
}
assigns =
assign_new(assigns, :class, fn ->
["btn", Map.fetch!(variants, assigns[:variant])]
end)
assign(assigns, :class, [
"inline-flex items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-semibold transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-60",
Map.fetch!(variants, assigns[:variant]),
assigns[:class]
])
if rest[:href] || rest[:navigate] || rest[:patch] do
~H"""
@@ -181,8 +205,11 @@ defmodule ChesstrainerWeb.CoreComponents do
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
attr :class, :any, default: nil, doc: "the input class to use over defaults"
attr :error_class, :any, default: nil, doc: "the input error class to use over defaults"
attr :class, :any, default: nil, doc: "extra classes merged with the default input classes"
attr :error_class, :any,
default: nil,
doc: "extra classes merged with the default error classes"
attr :rest, :global,
include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength
@@ -212,8 +239,8 @@ defmodule ChesstrainerWeb.CoreComponents do
end)
~H"""
<div class="fieldset mb-2">
<label for={@id}>
<div class="mb-3">
<label for={@id} class="flex items-center gap-2">
<input
type="hidden"
name={@name}
@@ -221,17 +248,16 @@ defmodule ChesstrainerWeb.CoreComponents do
disabled={@rest[:disabled]}
form={@rest[:form]}
/>
<span class="label">
<input
type="checkbox"
id={@id}
name={@name}
value="true"
checked={@checked}
class={@class || "checkbox checkbox-sm"}
{@rest}
/>{@label}
</span>
<input
type="checkbox"
id={@id}
name={@name}
value="true"
checked={@checked}
class={[checkbox_class(), @class]}
{@rest}
/>
<span class="text-sm text-base-content">{@label}</span>
</label>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
@@ -240,13 +266,17 @@ defmodule ChesstrainerWeb.CoreComponents do
def input(%{type: "select"} = assigns) do
~H"""
<div class="fieldset mb-2">
<div class="mb-3">
<label for={@id}>
<span :if={@label} class="label mb-1">{@label}</span>
<span :if={@label} class={label_class()}>{@label}</span>
<select
id={@id}
name={@name}
class={[@class || "w-full select", @errors != [] && (@error_class || "select-error")]}
class={[
input_class(),
@errors != [] && (@error_class || input_error_class()),
@class
]}
multiple={@multiple}
{@rest}
>
@@ -261,15 +291,16 @@ defmodule ChesstrainerWeb.CoreComponents do
def input(%{type: "textarea"} = assigns) do
~H"""
<div class="fieldset mb-2">
<div class="mb-3">
<label for={@id}>
<span :if={@label} class="label mb-1">{@label}</span>
<span :if={@label} class={label_class()}>{@label}</span>
<textarea
id={@id}
name={@name}
class={[
@class || "w-full textarea",
@errors != [] && (@error_class || "textarea-error")
input_class(),
@errors != [] && (@error_class || input_error_class()),
@class
]}
{@rest}
>{Phoenix.HTML.Form.normalize_value("textarea", @value)}</textarea>
@@ -282,17 +313,18 @@ defmodule ChesstrainerWeb.CoreComponents do
# All other inputs text, datetime-local, url, password, etc. are handled here...
def input(assigns) do
~H"""
<div class="fieldset mb-2">
<div class="mb-3">
<label for={@id}>
<span :if={@label} class="label mb-1">{@label}</span>
<span :if={@label} class={label_class()}>{@label}</span>
<input
type={@type}
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
@class || "w-full input",
@errors != [] && (@error_class || "input-error")
input_class(),
@errors != [] && (@error_class || input_error_class()),
@class
]}
{@rest}
/>
@@ -367,7 +399,7 @@ defmodule ChesstrainerWeb.CoreComponents do
end
~H"""
<table class="table table-zebra">
<table class={table_class()}>
<thead>
<tr>
<th :for={col <- @col}>{col[:label]}</th>
@@ -414,17 +446,49 @@ defmodule ChesstrainerWeb.CoreComponents do
def list(assigns) do
~H"""
<ul class="list">
<li :for={item <- @item} class="list-row">
<div class="list-col-grow">
<div class="font-bold">{item.title}</div>
<div>{render_slot(item)}</div>
<ul class="divide-y divide-base-200">
<li :for={item <- @item} class="flex gap-3 py-3">
<div class="flex-1 space-y-1">
<div class="font-semibold">{item.title}</div>
<div class="text-sm text-base-content/70">{render_slot(item)}</div>
</div>
</li>
</ul>
"""
end
@doc """
Renders a small pill label.
## Examples
<.badge>Lucena</.badge>
<.badge color="primary" size="sm">KR v K</.badge>
"""
attr :color, :string, default: "neutral", values: ~w(neutral primary warning)
attr :size, :string, default: "md", values: ~w(sm md)
attr :class, :any, default: nil
attr :rest, :global
slot :inner_block, required: true
def badge(assigns) do
~H"""
<span
class={[
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium",
@size == "sm" && "px-1.5 text-[0.7rem]",
@color == "neutral" && "bg-base-200 text-base-content",
@color == "primary" && "bg-primary/15 text-primary",
@color == "warning" && "bg-warning/15 text-warning",
@class
]}
{@rest}
>
{render_slot(@inner_block)}
</span>
"""
end
@doc """
Renders a [Heroicon](https://heroicons.com).
+24 -15
View File
@@ -129,7 +129,7 @@ defmodule ChesstrainerWeb.EndgameList do
~H"""
<div class="mb-6 space-y-3">
<div :if={@selected_themes != []} class="flex flex-wrap gap-2">
<span :for={theme <- @selected_themes} class="badge badge-primary gap-1">
<.badge :for={theme <- @selected_themes} color="primary">
{theme.name}
<button
type="button"
@@ -139,24 +139,30 @@ defmodule ChesstrainerWeb.EndgameList do
>
×
</button>
</span>
</.badge>
</div>
<div class="flex flex-col gap-3 sm:flex-row">
<form id="theme-filter-form" phx-change="search_themes" class="flex-1">
<input
type="text"
<.input
name="theme_search"
value={@theme_query}
phx-debounce="200"
autocomplete="off"
placeholder="Filter by theme…"
class="input input-bordered w-full"
/>
<ul :if={@theme_results != []} class="menu bg-base-100 rounded-box mt-2">
<ul
:if={@theme_results != []}
class="mt-2 w-full rounded-md border border-base-300 bg-base-100 p-1 shadow-sm"
>
<li :for={theme <- @theme_results}>
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>
<button
type="button"
phx-click="add_theme"
phx-value-id={theme.id}
class="block w-full rounded px-3 py-2 text-left text-sm hover:bg-base-200"
>
{theme.name}
</button>
</li>
@@ -164,12 +170,13 @@ defmodule ChesstrainerWeb.EndgameList do
</form>
<form id="key-filter-form" phx-change="filter_key" class="flex-1">
<select name="key" class="select w-full">
<option value="" selected={is_nil(@selected_key)}>All keys</option>
<option :for={key <- @keys} value={key} selected={key == @selected_key}>
{key}
</option>
</select>
<.input
type="select"
name="key"
prompt="All keys"
options={@keys}
value={@selected_key}
/>
</form>
</div>
@@ -202,7 +209,9 @@ defmodule ChesstrainerWeb.EndgameList do
>
<span class="font-semibold">{group.key}</span>
<span class="flex items-center gap-2 text-sm">
<span class="badge">{group.count}</span>
<.badge id={"key-group-count-" <> String.replace(group.key, " ", "-")}>
{group.count}
</.badge>
<.icon
name={if group.expanded, do: "hero-chevron-down", else: "hero-chevron-right"}
class="size-4"
@@ -210,7 +219,7 @@ defmodule ChesstrainerWeb.EndgameList do
</span>
</button>
<table :if={group.expanded} class="table table-zebra">
<table :if={group.expanded} class={table_class()}>
<thead>
{render_slot(@header)}
</thead>
@@ -0,0 +1,328 @@
defmodule ChesstrainerWeb.LandingComponents do
@moduledoc """
Presentational primitives for the marketing landing page.
Kept separate from `ChesstrainerWeb.CoreComponents`: the landing page uses a
distinct pill-button language, while CoreComponents provides the compact
admin and auth UI.
"""
use Phoenix.Component
alias Chesstrainer.FEN
alias Chesstrainer.Themes
@button_variants %{
nav: "nav-cta",
primary: "primary-button",
light: "light-button"
}
@files ~w(a b c d e f g h)
@piece_glyphs %{
"K" => "♔",
"Q" => "♕",
"R" => "♖",
"B" => "♗",
"N" => "♘",
"P" => "♙",
"k" => "♚",
"q" => "♛",
"r" => "♜",
"b" => "♝",
"n" => "♞",
"p" => "♟"
}
@fallback_fen "8/5k2/8/3K4/8/6R1/8/8 w - - 0 1"
@doc """
Renders a landing-page pill button.
Renders a link when given `href`, `navigate`, or `patch`; otherwise a button.
## Examples
<.pill_button variant={:nav} href="/#trainer">Start training</.pill_button>
<.pill_button variant={:primary} phx-click="go">Go</.pill_button>
"""
attr :rest, :global, include: ~w(href navigate patch method type disabled)
attr :variant, :atom, values: [:nav, :primary, :light], default: :nav
attr :class, :any, default: nil
slot :inner_block, required: true
def pill_button(%{rest: rest} = assigns) do
assigns =
assign(assigns, :class, [Map.fetch!(@button_variants, assigns.variant), assigns.class])
if rest[:href] || rest[:navigate] || rest[:patch] do
~H"""
<.link class={@class} {@rest}>
{render_slot(@inner_block)}
</.link>
"""
else
~H"""
<button class={@class} {@rest}>
{render_slot(@inner_block)}
</button>
"""
end
end
@doc """
Renders a static board preview for the landing page.
Accepts an endgame map with `:fen`, `:color` and `:key`; falls back to a
neutral position when no endgame is given. For an interactive board inside a
LiveView, use `board_grid/1` directly.
"""
attr :endgame, :map, default: nil
def board_preview(assigns) do
endgame = assigns.endgame
assigns =
assign(assigns,
fen: fen_for(endgame),
turn: turn_label(endgame),
title: title(endgame),
themes: theme_names(endgame),
orientation: orientation(endgame)
)
~H"""
<div class="board-shell">
<div class="board-topline">
<div class="player">
<span class="player-piece dark-piece">♚</span>
<span>
<small>To move</small>
<strong>{@turn}</strong>
</span>
</div>
</div>
<.board_grid fen={@fen} orientation={@orientation} />
<div class="board-caption">
<div>
<span>Today’s position</span>
<strong>{@title}</strong>
<small :if={@themes != []} class="board-themes">{Enum.join(@themes, " · ")}</small>
</div>
</div>
</div>
"""
end
@doc """
Renders the squares of a chess position.
Set `interactive` inside a LiveView to emit `phx-click="square"` events with
`phx-value-square` (for example `"e4"`). `selected` and `targets` are square
keys in algebraic notation.
"""
attr :fen, :string, required: true
attr :orientation, :atom, values: [:white, :black], default: :white
attr :selected, :string, default: nil
attr :targets, :list, default: []
attr :interactive, :boolean, default: false
attr :disabled, :boolean, default: false
attr :target, :any, default: nil
def board_grid(assigns) do
rows = FEN.board(assigns.fen) || FEN.board(@fallback_fen)
squares = board_squares(rows, assigns.orientation, assigns.selected, assigns.targets)
assigns = assign(assigns, :squares, squares)
~H"""
<div class="chessboard" aria-label="Chess position">
<%= for square <- @squares do %>
<div class={[
"square",
if(square.light, do: "light", else: "dark"),
square.selected? && "selected",
square.target? && "target"
]}>
<span :if={square.label_rank} class="rank">{square.rank}</span>
<span :if={square.label_file} class="file">{square.file}</span>
<span
:if={square.piece}
class={["piece", if(square.white, do: "white-piece", else: "black-piece")]}
>
{square.glyph}
</span>
</div>
<% end %>
</div>
"""
end
@doc """
Renders a curated endgame card for the landing-page grid.
The card links straight to the puzzle's player-facing play route.
"""
attr :endgame, :map, required: true
attr :index, :integer, required: true
attr :active, :boolean, default: false
def puzzle_card(assigns) do
~H"""
<.link
navigate={"/endgames/#{@endgame.public_code}/play"}
class={["puzzle-card", @active && "active"]}
>
<span class="card-number">{card_number(@index)}</span>
<span class="mini-piece">{mini_piece(@endgame)}</span>
<span class="difficulty">{difficulty(@endgame.rating)}</span>
<strong>{title(@endgame)}</strong>
<small>{meta(@endgame)}</small>
<span class="card-arrow"><.icon_arrow /></span>
</.link>
"""
end
@doc """
Formats the puzzle count for the landing-page stat.
Counts below 100 are shown exactly. Larger counts are floored to the nearest
hundred or thousand and suffixed with `+`, so the claim is never overstated.
"""
def puzzle_count_label(count) when is_integer(count) and count < 100 do
Integer.to_string(count)
end
def puzzle_count_label(count) when is_integer(count) and count < 1000 do
"#{div(count, 100) * 100}+"
end
def puzzle_count_label(count) when is_integer(count) do
"#{div(count, 1000) * 1000}+"
end
@doc "The spark used by the landing-page eyebrow."
def icon_spark(assigns) do
~H"""
<svg aria-hidden="true" viewBox="0 0 20 20" fill="none">
<path
d="M10 1.75c.33 3.25 1.85 4.77 5.1 5.1-3.25.33-4.77 1.85-5.1 5.1-.33-3.25-1.85-4.77-5.1-5.1 3.25-.33 4.77-1.85 5.1-5.1Z"
fill="currentColor"
/>
<path
d="M15.25 11.5c.18 1.8.95 2.57 2.75 2.75-1.8.18-2.57.95-2.75 2.75-.18-1.8-.95-2.57-2.75-2.75 1.8-.18 2.57-.95 2.75-2.75Z"
fill="currentColor"
/>
</svg>
"""
end
@doc "The arrow used by landing-page CTAs."
def icon_arrow(assigns) do
~H"""
<svg aria-hidden="true" viewBox="0 0 20 20" fill="none">
<path
d="M4 10h11m-4.5-4.5L15 10l-4.5 4.5"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
"""
end
defp board_squares(rows, orientation, selected, targets) do
rows
|> Enum.with_index()
|> Enum.flat_map(fn {row, r} ->
row
|> Enum.with_index()
|> Enum.map(fn {piece, c} ->
rank = 8 - r
file = Enum.at(@files, c)
key = "#{file}#{rank}"
%{
key: key,
rank: rank,
file: file,
file_index: c,
light: rem(c + rank, 2) == 0,
piece: piece,
glyph: piece_glyph(piece),
white: piece != nil and piece == String.upcase(piece),
selected?: selected == key,
target?: key in targets,
label_rank: (orientation == :black and c == 7) or (orientation != :black and c == 0),
label_file:
(orientation == :black and rank == 8) or (orientation != :black and rank == 1)
}
end)
end)
|> Enum.sort_by(&display_key(&1, orientation))
end
defp display_key(square, :black), do: {square.rank - 1, 7 - square.file_index}
defp display_key(square, _orientation), do: {8 - square.rank, square.file_index}
defp piece_glyph(nil), do: nil
defp piece_glyph(piece), do: Map.get(@piece_glyphs, piece)
defp square_label(%{piece: piece} = square) when is_binary(piece) do
"#{square.key}, #{square.glyph}"
end
defp square_label(square), do: square.key
defp fen_for(%{fen: fen}) when is_binary(fen), do: fen
defp fen_for(_endgame), do: @fallback_fen
defp turn_label(:black), do: "Black"
defp turn_label(:white), do: "White"
defp turn_label(%{color: color}), do: turn_label(color)
defp turn_label(%{fen: fen}) when is_binary(fen), do: turn_label(FEN.color_from_fen(fen))
defp turn_label(_endgame), do: "White"
defp title(%{key: key}) when is_binary(key) and key != "", do: key
defp title(%{message: message}) when is_binary(message) and message != "", do: message
defp title(_endgame), do: "Featured position"
defp theme_names(%{themes: themes}) when is_list(themes), do: Themes.names(themes)
defp theme_names(_endgame), do: []
defp orientation(%{color: color}) when color in [:white, :black], do: color
defp orientation(_endgame), do: :white
defp card_number(index), do: (index + 1) |> Integer.to_string() |> String.pad_leading(2, "0")
defp mini_piece(%{key: key}) when is_binary(key) do
cond do
String.contains?(key, "Q") -> "♛"
String.contains?(key, "R") -> "♖"
String.contains?(key, "B") -> "♗"
String.contains?(key, "N") -> "♘"
true -> "♙"
end
end
defp mini_piece(_endgame), do: "♙"
defp difficulty(rating) when is_number(rating) and rating < 1600, do: "Beginner"
defp difficulty(rating) when is_number(rating) and rating < 1900, do: "Intermediate"
defp difficulty(_rating), do: "Advanced"
defp meta(%{themes: themes, rating: rating}) when is_list(themes) do
case Themes.names(themes) do
[] -> rating_label(rating)
names -> Enum.join(names, " · ")
end
end
defp meta(%{rating: rating}), do: rating_label(rating)
defp rating_label(nil), do: "Unrated"
defp rating_label(rating), do: "Rating #{round(rating)}"
end
+137 -50
View File
@@ -52,57 +52,125 @@ defmodule ChesstrainerWeb.Layouts do
@doc """
Renders the application navbar.
The marketing and account links are defined once in `nav_links/1` and rendered
in both the desktop bar and the mobile menu. Edit that list to change what
appears in either place.
"""
attr :current_scope, :map,
default: nil,
doc: "the current [scope](https://phoenix.hexdocs.pm/scopes.html)"
def navbar(assigns) do
assigns = assign(assigns, :nav_links, nav_links(assigns.current_scope))
~H"""
<header class="navbar px-4 sm:px-6 lg:px-8">
<div class="flex-1">
<a href="/" class="flex-1 flex w-fit items-center gap-2">
<img src={~p"/images/logo.svg"} width="36" />
<span class="text-sm font-semibold">v{Application.spec(:phoenix, :vsn)}</span>
<header>
<nav class="nav-wrap" aria-label="Main navigation">
<a class="brand" href="/" aria-label="Lucid Chess home">
<span class="brand-mark">♞</span>
<span>LUCID</span>
</a>
</div>
<div class="flex-none">
<ul class="flex flex-column px-1 space-x-4 items-center">
<li>
<a href="/endgames" class="btn btn-ghost">Endgames</a>
</li>
<li :if={@current_scope && Role.admin?(@current_scope.user.role)}>
<a href="/admin/endgames" class="btn btn-ghost">Admin</a>
</li>
<li>
<.theme_toggle />
</li>
<%= if @current_scope do %>
<li>
<span class="text-sm">{@current_scope.user.username}</span>
</li>
<li>
<.link navigate={~p"/users/settings"} class="btn btn-ghost">Settings</.link>
</li>
<li>
<.link href={~p"/users/log-out"} method="delete" class="btn btn-ghost">
Log out
</.link>
</li>
<% else %>
<li>
<.link navigate={~p"/users/register"} class="btn btn-ghost">Register</.link>
</li>
<li>
<.link navigate={~p"/users/log-in"} class="btn btn-primary">Log in</.link>
</li>
<% end %>
</ul>
</div>
<div class="nav-right">
<.colour_mode_toggle />
<button
class="menu-button"
type="button"
aria-expanded="false"
aria-controls="nav-links"
aria-label="Toggle menu"
>
<span></span>
<span></span>
</button>
<div class="nav-links" id="nav-links">
<%= for link <- @nav_links do %>
<%= if link[:kind] == :text do %>
<span class="nav-user">{link.label}</span>
<% else %>
<.link href={link.href} method={link[:method]}>{link.label}</.link>
<% end %>
<% end %>
<.pill_button variant={:nav} href="/endgames">
Start training <.icon_arrow />
</.pill_button>
</div>
</div>
</nav>
</header>
"""
end
defp nav_links(scope) do
marketing = [
%{label: "Puzzle Search", href: "/#puzzles"}
]
admin =
if admin?(scope) do
[%{label: "Admin", href: ~p"/admin/endgames"}]
else
[]
end
account =
case scope do
%{user: %{username: username}} ->
[
%{label: username, kind: :text},
%{label: "Settings", href: ~p"/users/settings"},
%{label: "Log out", href: ~p"/users/log-out", method: "delete"}
]
_ ->
[
%{label: "Log in", href: ~p"/users/log-in"},
%{label: "Register", href: ~p"/users/register"}
]
end
marketing ++ admin ++ account
end
defp admin?(%{user: %{role: role}}), do: Role.admin?(role)
defp admin?(_scope), do: false
@doc """
Renders the site-wide footer.
Rendered once from the root layout so it appears on every page, matching the
navbar. Links to the landing-page anchors keep working from other pages
because they point at `/` first.
"""
def footer(assigns) do
assigns = assign(assigns, :year, DateTime.utc_now().year)
~H"""
<footer class="site-footer">
<div class="footer-brand">
<a class="brand" href="/" aria-label="Lucid Chess home">
<span class="brand-mark">♞</span>
<span>LUCID</span>
</a>
<p>Short, focused endgame training.</p>
</div>
<nav class="footer-links" aria-label="Footer">
<a href="/#method">Method</a>
<a href="/#puzzles">Puzzles</a>
<a href="/#progress">Progress</a>
<a href={~p"/endgames"}>Endgames</a>
</nav>
<small>© {@year} Lucid Chess</small>
</footer>
"""
end
@doc """
Shows the flash group with standard titles and content.
@@ -153,35 +221,54 @@ defmodule ChesstrainerWeb.Layouts do
end
@doc """
Provides dark vs light theme toggle based on themes defined in app.css.
Provides the system / light / dark colour-mode switch.
See <head> in root.html.heex which applies the theme before page load.
The click handling and `aria-checked` syncing live in the script in
`root.html.heex`, which runs before paint and also on pages without LiveView
(the landing page uses the marketing bundle).
"""
def theme_toggle(assigns) do
def colour_mode_toggle(assigns) do
~H"""
<div class="card relative flex flex-row items-center border-2 border-base-300 bg-base-300 rounded-full">
<div class="absolute w-1/3 h-full rounded-full border-1 border-base-200 bg-base-100 brightness-200 left-0 [[data-theme=light]_&]:left-1/3 [[data-theme=dark]_&]:left-2/3 [[data-theme-source=system]_&]:!left-0 transition-[left]" />
<div
class="relative flex flex-row items-center rounded-full border-2 border-base-300 bg-base-300"
role="radiogroup"
aria-label="Colour mode"
>
<div
class="absolute w-1/3 h-full rounded-full border border-base-200 bg-base-100 brightness-200 left-0 [[data-theme=light]_&]:left-1/3 [[data-theme=dark]_&]:left-2/3 [[data-theme-source=system]_&]:!left-0 transition-[left]"
aria-hidden="true"
>
</div>
<button
class="flex p-2 cursor-pointer w-1/3"
phx-click={JS.dispatch("phx:set-theme")}
type="button"
class="flex p-2 cursor-pointer w-1/3 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
data-phx-theme="system"
role="radio"
aria-checked="true"
aria-label="System colour mode"
>
<.icon name="hero-computer-desktop-micro" class="size-4 opacity-75 hover:opacity-100" />
</button>
<button
class="flex p-2 cursor-pointer w-1/3"
phx-click={JS.dispatch("phx:set-theme")}
type="button"
class="flex p-2 cursor-pointer w-1/3 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
data-phx-theme="light"
role="radio"
aria-checked="false"
aria-label="Light colour mode"
>
<.icon name="hero-sun-micro" class="size-4 opacity-75 hover:opacity-100" />
</button>
<button
class="flex p-2 cursor-pointer w-1/3"
phx-click={JS.dispatch("phx:set-theme")}
type="button"
class="flex p-2 cursor-pointer w-1/3 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
data-phx-theme="dark"
role="radio"
aria-checked="false"
aria-label="Dark colour mode"
>
<.icon name="hero-moon-micro" class="size-4 opacity-75 hover:opacity-100" />
</button>
@@ -3,37 +3,135 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="csrf-token" content={get_csrf_token()} />
<.live_title default="Chesstrainer" suffix=" · Phoenix Framework" phx-no-format>{assigns[:page_title]}</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/js/app.js"}>
<meta name="csrf-token" content={get_csrf_token()} />
<.live_title
default="Lucid Chess — Endgame Trainer"
suffix={assigns[:title_suffix] || " · Lucid Chess"}
phx-no-format
>{assigns[:page_title]}</.live_title>
<meta
:if={assigns[:meta_description]}
name="description"
content={assigns[:meta_description]}
/>
<link :if={assigns[:canonical_url]} rel="canonical" href={assigns[:canonical_url]} />
<meta :if={assigns[:meta_description]} property="og:type" content="website" />
<meta :if={assigns[:meta_description]} property="og:site_name" content="Lucid Chess" />
<meta
:if={assigns[:meta_description]}
property="og:title"
content={assigns[:page_title] || "Lucid Chess — Endgame Trainer"}
/>
<meta
:if={assigns[:meta_description]}
property="og:description"
content={assigns[:meta_description]}
/>
<meta :if={assigns[:canonical_url]} property="og:url" content={assigns[:canonical_url]} />
<meta :if={assigns[:meta_description]} name="twitter:card" content="summary" />
<meta
:if={assigns[:meta_description]}
name="twitter:title"
content={assigns[:page_title] || "Lucid Chess — Endgame Trainer"}
/>
<meta
:if={assigns[:meta_description]}
name="twitter:description"
content={assigns[:meta_description]}
/>
<link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} />
<link
rel="preload"
href="/fonts/dm-sans-variable.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="/fonts/dm-serif-display.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<script
defer
phx-track-static
type="text/javascript"
src={assigns[:js_entry] || ~p"/assets/js/app.js"}
>
</script>
<script>
(() => {
const systemTheme = () => matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
const systemMode = () => matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
const setTheme = (theme) => {
if (theme === "system") {
localStorage.removeItem("phx:theme");
document.documentElement.setAttribute("data-theme", systemTheme());
document.documentElement.setAttribute("data-theme-source", "system");
} else {
localStorage.setItem("phx:theme", theme);
document.documentElement.setAttribute("data-theme", theme);
document.documentElement.setAttribute("data-theme-source", "user");
const storedMode = () => {
try { return localStorage.getItem("phx:theme"); } catch (_) { return null; }
};
const persistMode = (mode) => {
try {
if (mode === "system") localStorage.removeItem("phx:theme");
else localStorage.setItem("phx:theme", mode);
} catch (_) {
// Storage can be blocked (private modes, embedded browsers); the
// mode still applies for this page load.
}
};
if (!document.documentElement.hasAttribute("data-theme")) {
setTheme(localStorage.getItem("phx:theme") || "system");
}
window.addEventListener("storage", (e) => e.key === "phx:theme" && setTheme(e.newValue || "system"));
window.addEventListener("phx:set-theme", (e) => setTheme(e.target.dataset.phxTheme));
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
const selectedMode = () => {
const source = document.documentElement.getAttribute("data-theme-source");
return source === "system" ? "system" : document.documentElement.getAttribute("data-theme");
};
const syncChecked = () => {
document.querySelectorAll("[data-phx-theme]").forEach((button) => {
button.setAttribute("aria-checked", String(button.dataset.phxTheme === selectedMode()));
});
};
const setMode = (mode) => {
if (mode !== "system" && mode !== "light" && mode !== "dark") return;
if (mode === "system") {
persistMode("system");
document.documentElement.setAttribute("data-theme", systemMode());
document.documentElement.setAttribute("data-theme-source", "system");
} else {
persistMode(mode);
document.documentElement.setAttribute("data-theme", mode);
document.documentElement.setAttribute("data-theme-source", "user");
}
syncChecked();
};
if (!document.documentElement.hasAttribute("data-theme")) {
setMode(storedMode() || "system");
}
document.addEventListener("DOMContentLoaded", syncChecked);
// Plain DOM so the switch also works on controller-rendered pages
// (the landing page ships no LiveView runtime).
document.addEventListener("click", (event) => {
const button = event.target instanceof Element && event.target.closest("[data-phx-theme]");
if (button) setMode(button.dataset.phxTheme);
});
window.addEventListener("storage", (event) => {
if (event.key === "phx:theme") setMode(event.newValue || "system");
});
window.addEventListener("phx:set-theme", (event) => {
setMode(event.target?.dataset?.phxTheme);
});
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
if (document.documentElement.getAttribute("data-theme-source") === "system") {
document.documentElement.setAttribute("data-theme", systemTheme());
document.documentElement.setAttribute("data-theme", systemMode());
}
});
})();
@@ -42,5 +140,6 @@
<body>
<Layouts.navbar current_scope={@current_scope} />
{@inner_content}
<Layouts.footer />
</body>
</html>
@@ -1,7 +1,25 @@
defmodule ChesstrainerWeb.PageController do
use ChesstrainerWeb, :controller
alias Chesstrainer.DailyPuzzles
alias Chesstrainer.Endgames
@description "Short, focused endgame puzzles against tablebase-perfect defence. " <>
"Learn to see the winning move and make the endgame your strongest phase."
def home(conn, _params) do
render(conn, :home)
endgames = Endgames.curated_endgames()
conn
|> assign(:js_entry, ~p"/assets/js/marketing.js")
|> assign(:page_title, "Lucid Chess — Endgame Trainer")
|> assign(:title_suffix, "")
|> assign(:meta_description, @description)
|> assign(:canonical_url, current_url(conn))
|> render(:home,
endgames: endgames,
active_endgame: DailyPuzzles.today(),
puzzle_count: Endgames.count_endgames()
)
end
end
@@ -7,4 +7,7 @@ defmodule ChesstrainerWeb.PageHTML do
use ChesstrainerWeb, :html
embed_templates "page_html/*"
defp play_path(nil), do: ~p"/endgames"
defp play_path(%{public_code: public_code}), do: ~p"/endgames/#{public_code}/play"
end
@@ -1,160 +1,89 @@
<Layouts.flash_group flash={@flash} />
<div class="px-4 py-10 sm:px-6 sm:py-28 lg:px-8 xl:px-28 xl:py-32">
<div class="mx-auto max-w-xl lg:mx-0">
<svg viewBox="0 0 71 48" class="h-12" aria-hidden="true">
<path
d="m26.371 33.477-.552-.1c-3.92-.729-6.397-3.1-7.57-6.829-.733-2.324.597-4.035 3.035-4.148 1.995-.092 3.362 1.055 4.57 2.39 1.557 1.72 2.984 3.558 4.514 5.305 2.202 2.515 4.797 4.134 8.347 3.634 3.183-.448 5.958-1.725 8.371-3.828.363-.316.761-.592 1.144-.886l-.241-.284c-2.027.63-4.093.841-6.205.735-3.195-.16-6.24-.828-8.964-2.582-2.486-1.601-4.319-3.746-5.19-6.611-.704-2.315.736-3.934 3.135-3.6.948.133 1.746.56 2.463 1.165.583.493 1.143 1.015 1.738 1.493 2.8 2.25 6.712 2.375 10.265-.068-5.842-.026-9.817-3.24-13.308-7.313-1.366-1.594-2.7-3.216-4.095-4.785-2.698-3.036-5.692-5.71-9.79-6.623C12.8-.623 7.745.14 2.893 2.361 1.926 2.804.997 3.319 0 4.149c.494 0 .763.006 1.032 0 2.446-.064 4.28 1.023 5.602 3.024.962 1.457 1.415 3.104 1.761 4.798.513 2.515.247 5.078.544 7.605.761 6.494 4.08 11.026 10.26 13.346 2.267.852 4.591 1.135 7.172.555ZM10.751 3.852c-.976.246-1.756-.148-2.56-.962 1.377-.343 2.592-.476 3.897-.528-.107.848-.607 1.306-1.336 1.49Zm32.002 37.924c-.085-.626-.62-.901-1.04-1.228-1.857-1.446-4.03-1.958-6.333-2-1.375-.026-2.735-.128-4.031-.61-.595-.22-1.26-.505-1.244-1.272.015-.78.693-1 1.31-1.184.505-.15 1.026-.247 1.6-.382-1.46-.936-2.886-1.065-4.787-.3-2.993 1.202-5.943 1.06-8.926-.017-1.684-.608-3.179-1.563-4.735-2.408l-.043.03a2.96 2.96 0 0 0 .04-.029c-.038-.117-.107-.12-.197-.054l.122.107c1.29 2.115 3.034 3.817 5.004 5.271 3.793 2.8 7.936 4.471 12.784 3.73A66.714 66.714 0 0 1 37 40.877c1.98-.16 3.866.398 5.753.899Zm-9.14-30.345c-.105-.076-.206-.266-.42-.069 1.745 2.36 3.985 4.098 6.683 5.193 4.354 1.767 8.773 2.07 13.293.51 3.51-1.21 6.033-.028 7.343 3.38.19-3.955-2.137-6.837-5.843-7.401-2.084-.318-4.01.373-5.962.94-5.434 1.575-10.485.798-15.094-2.553Zm27.085 15.425c.708.059 1.416.123 2.124.185-1.6-1.405-3.55-1.517-5.523-1.404-3.003.17-5.167 1.903-7.14 3.972-1.739 1.824-3.31 3.87-5.903 4.604.043.078.054.117.066.117.35.005.699.021 1.047.005 3.768-.17 7.317-.965 10.14-3.7.89-.86 1.685-1.817 2.544-2.71.716-.746 1.584-1.159 2.645-1.07Zm-8.753-4.67c-2.812.246-5.254 1.409-7.548 2.943-1.766 1.18-3.654 1.738-5.776 1.37-.374-.066-.75-.114-1.124-.17l-.013.156c.135.07.265.151.405.207.354.14.702.308 1.07.395 4.083.971 7.992.474 11.516-1.803 2.221-1.435 4.521-1.707 7.013-1.336.252.038.503.083.756.107.234.022.479.255.795.003-2.179-1.574-4.526-2.096-7.094-1.872Zm-10.049-9.544c1.475.051 2.943-.142 4.486-1.059-.452.04-.643.04-.827.076-2.126.424-4.033-.04-5.733-1.383-.623-.493-1.257-.974-1.889-1.457-2.503-1.914-5.374-2.555-8.514-2.5.05.154.054.26.108.315 3.417 3.455 7.371 5.836 12.369 6.008Zm24.727 17.731c-2.114-2.097-4.952-2.367-7.578-.537 1.738.078 3.043.632 4.101 1.728.374.388.763.768 1.182 1.106 1.6 1.29 4.311 1.352 5.896.155-1.861-.726-1.861-.726-3.601-2.452Zm-21.058 16.06c-1.858-3.46-4.981-4.24-8.59-4.008a9.667 9.667 0 0 1 2.977 1.39c.84.586 1.547 1.311 2.243 2.055 1.38 1.473 3.534 2.376 4.962 2.07-.656-.412-1.238-.848-1.592-1.507Zm17.29-19.32c0-.023.001-.045.003-.068l-.006.006.006-.006-.036-.004.021.018.012.053Zm-20 14.744a7.61 7.61 0 0 0-.072-.041.127.127 0 0 0 .015.043c.005.008.038 0 .058-.002Zm-.072-.041-.008-.034-.008.01.008-.01-.022-.006.005.026.024.014Z"
fill="#FD4F00"
/>
</svg>
<div class="mt-10 flex justify-between items-center">
<h1 class="flex items-center text-sm font-semibold leading-6">
Phoenix Framework
<small class="badge badge-warning badge-sm ml-3">
v{Application.spec(:phoenix, :vsn)}
</small>
<main>
<section class="hero">
<div class="hero-copy">
<div class="eyebrow">
<.icon_spark /> Endgames, made clear
</div>
<h1>
Learn to see the <em>winning move.</em>
</h1>
<Layouts.theme_toggle />
</div>
<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-balance">
Peace of mind from prototype to production.
</p>
<p class="mt-4 leading-7 text-base-content/70">
Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale.
</p>
<div class="flex">
<div class="w-full sm:w-auto">
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-3">
<a
href="https://phoenix.hexdocs.pm/overview.html"
class="group relative rounded-box px-6 py-4 text-sm font-semibold leading-6 sm:py-6"
>
<span class="absolute inset-0 rounded-box bg-base-200 transition group-hover:bg-base-300 sm:group-hover:scale-105"></span>
<span class="relative flex items-center gap-4 sm:flex-col">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class="h-6 w-6">
<path d="m12 4 10-2v18l-10 2V4Z" fill="currentColor" fill-opacity=".15" />
<path
d="M12 4 2 2v18l10 2m0-18v18m0-18 10-2v18l-10 2"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
Guides &amp; Docs
</span>
</a>
<a
href="https://github.com/phoenixframework/phoenix"
class="group relative rounded-box px-6 py-4 text-sm font-semibold leading-6 sm:py-6"
>
<span class="absolute inset-0 rounded-box bg-base-200 transition group-hover:bg-base-300 sm:group-hover:scale-105"></span>
<span class="relative flex items-center gap-4 sm:flex-col">
<svg viewBox="0 0 24 24" aria-hidden="true" class="h-6 w-6">
<path
fill="currentColor"
fill-rule="evenodd"
clip-rule="evenodd"
d="M12 0C5.37 0 0 5.506 0 12.303c0 5.445 3.435 10.043 8.205 11.674.6.107.825-.262.825-.585 0-.292-.015-1.261-.015-2.291C6 21.67 5.22 20.346 4.98 19.654c-.135-.354-.72-1.446-1.23-1.738-.42-.23-1.02-.8-.015-.815.945-.015 1.62.892 1.845 1.261 1.08 1.86 2.805 1.338 3.495 1.015.105-.8.42-1.338.765-1.645-2.67-.308-5.46-1.37-5.46-6.075 0-1.338.465-2.446 1.23-3.307-.12-.308-.54-1.569.12-3.26 0 0 1.005-.323 3.3 1.26.96-.276 1.98-.415 3-.415s2.04.139 3 .416c2.295-1.6 3.3-1.261 3.3-1.261.66 1.691.24 2.952.12 3.26.765.861 1.23 1.953 1.23 3.307 0 4.721-2.805 5.767-5.475 6.075.435.384.81 1.122.81 2.276 0 1.645-.015 2.968-.015 3.383 0 .323.225.707.825.585a12.047 12.047 0 0 0 5.919-4.489A12.536 12.536 0 0 0 24 12.304C24 5.505 18.63 0 12 0Z"
/>
</svg>
Source Code
</span>
</a>
<a
href={"https://github.com/phoenixframework/phoenix/blob/v#{Application.spec(:phoenix, :vsn)}/CHANGELOG.md"}
class="group relative rounded-box px-6 py-4 text-sm font-semibold leading-6 sm:py-6"
>
<span class="absolute inset-0 rounded-box bg-base-200 transition group-hover:bg-base-300 sm:group-hover:scale-105"></span>
<span class="relative flex items-center gap-4 sm:flex-col">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class="h-6 w-6">
<path
d="M12 1v6M12 17v6"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<circle
cx="12"
cy="12"
r="4"
fill="currentColor"
fill-opacity=".15"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
Changelog
</span>
</a>
</div>
<div class="mt-10 grid grid-cols-1 gap-y-4 text-sm leading-6 text-base-content/80 sm:grid-cols-2">
<div>
<a
href="https://elixirforum.com"
class="group -mx-2 -my-0.5 inline-flex items-center gap-3 rounded-lg px-2 py-0.5 hover:bg-base-200 hover:text-base-content"
>
<svg
viewBox="0 0 16 16"
aria-hidden="true"
class="h-4 w-4 fill-base-content/40 group-hover:fill-base-content"
>
<path d="M8 13.833c3.866 0 7-2.873 7-6.416C15 3.873 11.866 1 8 1S1 3.873 1 7.417c0 1.081.292 2.1.808 2.995.606 1.05.806 2.399.086 3.375l-.208.283c-.285.386-.01.905.465.85.852-.098 2.048-.318 3.137-.81a3.717 3.717 0 0 1 1.91-.318c.263.027.53.041.802.041Z" />
</svg>
Discuss on the Elixir Forum
</a>
</div>
<div>
<a
href="https://discord.gg/elixir"
class="group -mx-2 -my-0.5 inline-flex items-center gap-3 rounded-lg px-2 py-0.5 hover:bg-base-200 hover:text-base-content"
>
<svg
viewBox="0 0 16 16"
aria-hidden="true"
class="h-4 w-4 fill-base-content/40 group-hover:fill-base-content"
>
<path d="M13.545 2.995c-1.02-.46-2.114-.8-3.257-.994a.05.05 0 0 0-.052.024c-.141.246-.297.567-.406.82a12.377 12.377 0 0 0-3.658 0 8.238 8.238 0 0 0-.412-.82.052.052 0 0 0-.052-.024 13.315 13.315 0 0 0-3.257.994.046.046 0 0 0-.021.018C.356 6.063-.213 9.036.066 11.973c.001.015.01.029.02.038a13.353 13.353 0 0 0 3.996 1.987.052.052 0 0 0 .056-.018c.308-.414.582-.85.818-1.309a.05.05 0 0 0-.028-.069 8.808 8.808 0 0 1-1.248-.585.05.05 0 0 1-.005-.084c.084-.062.168-.126.248-.191a.05.05 0 0 1 .051-.007c2.619 1.176 5.454 1.176 8.041 0a.05.05 0 0 1 .053.006c.08.065.164.13.248.192a.05.05 0 0 1-.004.084c-.399.23-.813.423-1.249.585a.05.05 0 0 0-.027.07c.24.457.514.893.817 1.307a.051.051 0 0 0 .056.019 13.31 13.31 0 0 0 4.001-1.987.05.05 0 0 0 .021-.037c.334-3.396-.559-6.345-2.365-8.96a.04.04 0 0 0-.021-.02Zm-8.198 7.19c-.789 0-1.438-.712-1.438-1.587 0-.874.637-1.586 1.438-1.586.807 0 1.45.718 1.438 1.586 0 .875-.637 1.587-1.438 1.587Zm5.316 0c-.788 0-1.438-.712-1.438-1.587 0-.874.637-1.586 1.438-1.586.807 0 1.45.718 1.438 1.586 0 .875-.63 1.587-1.438 1.587Z" />
</svg>
Join our Discord server
</a>
</div>
<div>
<a
href="https://elixir-slack.community/"
class="group -mx-2 -my-0.5 inline-flex items-center gap-3 rounded-lg px-2 py-0.5 hover:bg-base-200 hover:text-base-content"
>
<svg
viewBox="0 0 16 16"
aria-hidden="true"
class="h-4 w-4 fill-base-content/40 group-hover:fill-base-content"
>
<path d="M3.361 10.11a1.68 1.68 0 1 1-1.68-1.681h1.68v1.682ZM4.209 10.11a1.68 1.68 0 1 1 3.361 0v4.21a1.68 1.68 0 1 1-3.361 0v-4.21ZM5.89 3.361a1.68 1.68 0 1 1 1.681-1.68v1.68H5.89ZM5.89 4.209a1.68 1.68 0 1 1 0 3.361H1.68a1.68 1.68 0 1 1 0-3.361h4.21ZM12.639 5.89a1.68 1.68 0 1 1 1.68 1.681h-1.68V5.89ZM11.791 5.89a1.68 1.68 0 1 1-3.361 0V1.68a1.68 1.68 0 0 1 3.361 0v4.21ZM10.11 12.639a1.68 1.68 0 1 1-1.681 1.68v-1.68h1.682ZM10.11 11.791a1.68 1.68 0 1 1 0-3.361h4.21a1.68 1.68 0 1 1 0 3.361h-4.21Z" />
</svg>
Join us on Slack
</a>
</div>
<div>
<a
href="https://fly.io/docs/elixir/getting-started/"
class="group -mx-2 -my-0.5 inline-flex items-center gap-3 rounded-lg px-2 py-0.5 hover:bg-base-200 hover:text-base-content"
>
<svg
viewBox="0 0 20 20"
aria-hidden="true"
class="h-4 w-4 fill-base-content/40 group-hover:fill-base-content"
>
<path d="M1 12.5A4.5 4.5 0 005.5 17H15a4 4 0 001.866-7.539 3.504 3.504 0 00-4.504-4.272A4.5 4.5 0 004.06 8.235 4.502 4.502 0 001 12.5z" />
</svg>
Deploy your application
</a>
</div>
<p>
Short, focused endgame sessions that build the instincts you need
when every move matters.
</p>
<div class="hero-actions">
<.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
Try today's puzzle <.icon_arrow />
</.pill_button>
<div class="rating-note">
<span class="avatar-stack">
<i>♟</i>
<i>♙</i>
<i>♜</i>
</span>
<span>
<strong>12,400+</strong> players training
</span>
</div>
</div>
</div>
</div>
</div>
<div class="board-stage" id="trainer">
<div class="coral-orbit" />
<div class="mint-orbit" />
<.board_preview endgame={@active_endgame} />
</div>
</section>
<section class="learning-strip" id="method">
<p>Built for the part of chess that decides everything.</p>
<div class="stat">
<strong>10</strong>
<span>minutes a day</span>
</div>
<div class="stat">
<strong>{puzzle_count_label(@puzzle_count)}</strong>
<span>puzzles</span>
</div>
<div class="stat">
<strong>3.2×</strong>
<span>faster pattern recall</span>
</div>
</section>
<section class="puzzle-section" id="puzzles">
<div class="section-heading">
<div>
<span class="section-kicker">Choose your challenge</span>
<h2>
One position. <br /> One clear idea.
</h2>
</div>
<p>
No noise, no endless variations. Each exercise teaches a pattern
you’ll recognize over the board.
</p>
</div>
<div class="puzzle-grid">
<%= for {endgame, index} <- Enum.with_index(@endgames) do %>
<.puzzle_card
endgame={endgame}
index={index}
active={@active_endgame && endgame.id == @active_endgame.id}
/>
<% end %>
</div>
</section>
<section class="progress-banner" id="progress">
<div>
<span class="section-kicker">A calmer way to improve</span>
<h2>
Make the endgame <br /> your strongest phase.
</h2>
</div>
<.pill_button variant={:light} navigate={play_path(@active_endgame)}>
Begin with the basics <.icon_arrow />
</.pill_button>
</section>
</main>
+35 -33
View File
@@ -16,25 +16,21 @@ defmodule ChesstrainerWeb.EndgameLive.Form do
<:subtitle>Use this form to manage endgame records in your database.</:subtitle>
</.header>
<div class="field mb-6">
<label class="label">
<span class="label-text">Themes</span>
</label>
<div class="mb-6">
<span class="mb-1 block text-sm font-medium text-base-content">Themes</span>
<div class="flex flex-wrap gap-2 mb-2">
<%= for theme <- @selected_themes do %>
<span class="badge badge-primary gap-1">
{theme.name}
<button
type="button"
phx-click="remove_theme"
phx-value-id={theme.id}
aria-label={"Remove #{theme.name}"}
>
×
</button>
</span>
<% end %>
<.badge :for={theme <- @selected_themes} color="primary">
{theme.name}
<button
type="button"
phx-click="remove_theme"
phx-value-id={theme.id}
aria-label={"Remove #{theme.name}"}
>
×
</button>
</.badge>
</div>
<form
@@ -42,30 +38,36 @@ defmodule ChesstrainerWeb.EndgameLive.Form do
phx-change="search_themes"
phx-submit="create_theme_from_search"
>
<input
type="text"
<.input
name="theme_search"
value={@theme_query}
phx-debounce="200"
autocomplete="off"
placeholder="Search or create a theme…"
class="input input-bordered w-full"
/>
<ul class="menu bg-base-100 rounded-box mt-2">
<%= for theme <- @theme_results do %>
<li>
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>{theme.name}</button>
</li>
<% end %>
<ul class="mt-2 w-full rounded-md border border-base-300 bg-base-100 p-1 shadow-sm">
<li :for={theme <- @theme_results}>
<button
type="button"
phx-click="add_theme"
phx-value-id={theme.id}
class="block w-full rounded px-3 py-2 text-left text-sm hover:bg-base-200"
>
{theme.name}
</button>
</li>
<%= if @can_create do %>
<li>
<button type="button" phx-click="create_theme" phx-value-name={@theme_query}>
Create theme "{String.trim(@theme_query)}"
</button>
</li>
<% end %>
<li :if={@can_create}>
<button
type="button"
phx-click="create_theme"
phx-value-name={@theme_query}
class="block w-full rounded px-3 py-2 text-left text-sm hover:bg-base-200"
>
Create theme "{String.trim(@theme_query)}"
</button>
</li>
</ul>
</form>
</div>
@@ -31,7 +31,6 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
label="Find by ID or FEN"
autocomplete="off"
placeholder="Public code, database id, or FEN…"
class="input input-bordered w-full"
/>
</div>
<.button variant="primary">Find</.button>
@@ -40,7 +39,12 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
<div :if={@search_query} id="endgame-search-results" class="space-y-3">
<div class="flex items-center justify-between">
<p class="text-sm text-base-content/70">Results for “{@search_query}”</p>
<button type="button" id="clear-endgame-search" phx-click="clear_search" class="link">
<button
type="button"
id="clear-endgame-search"
phx-click="clear_search"
class="text-sm text-primary underline underline-offset-4 hover:text-primary/80"
>
Clear
</button>
</div>
@@ -49,7 +53,7 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
No endgame matches “{@search_query}”.
</p>
<table :if={@search_results != []} class="table table-zebra">
<table :if={@search_results != []} class={table_class()}>
<thead>
<tr>
<th>Key</th>
@@ -115,11 +119,11 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
{endgame.result}
</td>
<td>
<span :for={theme <- endgame.themes} class="badge badge-sm">
<.badge :for={theme <- endgame.themes} size="sm">
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>
{theme.name}
</button>
</span>
</.badge>
<span :if={endgame.themes == []} class="text-base-content/50">None</span>
</td>
<td
+32 -32
View File
@@ -19,7 +19,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
0} · Solved: {@endgame.times_solved || 0}<span :if={@user_rating}> · Your rating: {round(
@user_rating
)}</span>
<p class="text-xs text-gray-500 flex items-center mt-1">
<p class="text-xs text-muted flex items-center mt-1">
<span>FEN: {@endgame.fen}</span>
<button
id="copy-fen-btn"
@@ -39,7 +39,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
</:actions>
</.header>
<div class="flex gap-2 bg-gray-200 p-4 rounded-xl shadow-inner">
<div class="flex gap-2 bg-base-200 p-4 rounded-xl shadow-inner">
<div
id="endgame-board"
phx-hook="ChessBoard"
@@ -50,78 +50,78 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
</div>
<div class="w-48 h-100 flex flex-col gap-3">
<div class="rounded-lg bg-white p-3 text-sm">
<div class="rounded-lg bg-canvas-raised p-3 text-sm">
<%= cond do %>
<% @status == :loading -> %>
<p class="text-gray-500">Loading tablebase…</p>
<p class="text-muted">Loading tablebase…</p>
<% @status == :blocked -> %>
<p class="font-semibold text-red-600">Tablebase unavailable</p>
<p class="text-red-500">{@blocked_reason}</p>
<p class="font-semibold text-error">Tablebase unavailable</p>
<p class="text-error">{@blocked_reason}</p>
<% @status == :solved -> %>
<p class="font-semibold text-emerald-600">
<p class="font-semibold text-success-text">
{if @endgame.result == :draw, do: "Draw held!", else: "Solved!"}
</p>
<% @status == :failed -> %>
<p class="font-semibold text-red-600">Failed</p>
<p class="text-red-500">
<p class="font-semibold text-error">Failed</p>
<p class="text-error">
{if @endgame.result == :draw,
do: "That move loses the draw.",
else: "That move throws away the win."}
</p>
<%= if @best_move && @plies != [] do %>
<p class="text-gray-600">
<p class="text-muted">
You played {List.last(@plies).san}; best was: {@best_move}
</p>
<% end %>
<% @awaiting_reply -> %>
<p class="text-gray-500">Opponent is replying…</p>
<p class="text-muted">Opponent is replying…</p>
<% @last_grade == :optimal -> %>
<p class="font-semibold text-emerald-600">Optimal move</p>
<p class="font-semibold text-success-text">Optimal move</p>
<% @last_grade == :winning -> %>
<p class="font-semibold text-amber-600">
<p class="font-semibold text-warning">
{if @endgame.result == :draw,
do: "Keeps the draw — but not the sharpest",
else: "Winning — but not the sharpest"}
</p>
<% @last_grade == :losing -> %>
<p class="font-semibold text-red-600">
<p class="font-semibold text-error">
{if @endgame.result == :draw,
do: "Losing move — this loses the draw",
else: "Losing move — this throws away the win"}
</p>
<% @last_grade == :unknown -> %>
<p class="font-semibold text-gray-600">Could not grade that move</p>
<p class="font-semibold text-muted">Could not grade that move</p>
<% true -> %>
<p class="text-gray-500">Make a move to have it graded.</p>
<p class="text-muted">Make a move to have it graded.</p>
<% end %>
</div>
<div :if={@reviewing} id="best-move-panel" class="rounded-lg bg-white p-3 text-sm">
<div :if={@reviewing} id="best-move-panel" class="rounded-lg bg-canvas-raised p-3 text-sm">
<%= cond do %>
<% @review_blocked -> %>
<p class="text-gray-500">Best move unavailable here</p>
<p class="text-gray-400">{@review_blocked}</p>
<p class="text-muted">Best move unavailable here</p>
<p class="text-muted">{@review_blocked}</p>
<% @review_tablebase -> %>
<p class="text-gray-600 font-semibold mb-1">Best move:</p>
<p class="text-emerald-600">{best_move_text(@review_tablebase) || "—"}</p>
<p class="text-muted font-semibold mb-1">Best move:</p>
<p class="text-success-text">{best_move_text(@review_tablebase) || "—"}</p>
<%= if played_ply = played_ply_at(@line, @review_index) do %>
<p class={["mt-1", grade_class(played_ply.grade)]}>Played: {played_ply.san}</p>
<% end %>
<% true -> %>
<p class="text-gray-500">No best move.</p>
<p class="text-muted">No best move.</p>
<% end %>
</div>
<div id="move-list" class="flex-1 min-h-0 flex flex-col bg-white rounded-lg p-3">
<div id="move-list" class="flex-1 min-h-0 flex flex-col bg-canvas-raised rounded-lg p-3">
<% plies = display_plies(@reviewing, @line, @plies) %>
<p class="text-sm text-gray-600 font-semibold mb-2">Moves:</p>
<p class="text-sm text-muted font-semibold mb-2">Moves:</p>
<div class="flex-1 overflow-y-auto">
<%= if plies == [] do %>
<p class="text-sm text-gray-500">No Moves</p>
<p class="text-sm text-muted">No Moves</p>
<% else %>
<%= for {[white_ply, black_ply], move_no} <- move_rows(plies, @endgame.color) do %>
<div class="font-mono text-sm leading-6">
<span class="text-gray-500 mr-2">{move_no}.</span>
<span class="text-muted mr-2">{move_no}.</span>
<%= if white_ply do %>
<.ply
ply={white_ply}
@@ -130,7 +130,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
result={@endgame.result}
/>
<% else %>
<span class="text-gray-900">...</span>
<span class="text-body">...</span>
<% end %>
<%= if black_ply do %>
<.ply
@@ -504,16 +504,16 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
end
end
defp ply_class(%{best_line: true}), do: "text-sky-600 italic"
defp ply_class(%{best_line: true}), do: "text-info italic"
defp ply_class(ply), do: grade_class(ply.grade)
defp ply_title(%{best_line: true}, _result), do: "Best line"
defp ply_title(ply, result), do: grade_label(ply.grade, result)
defp grade_class(:optimal), do: "text-emerald-600"
defp grade_class(:winning), do: "text-amber-600"
defp grade_class(:losing), do: "text-red-600"
defp grade_class(_), do: "text-gray-900"
defp grade_class(:optimal), do: "text-success-text"
defp grade_class(:winning), do: "text-warning"
defp grade_class(:losing), do: "text-error"
defp grade_class(_), do: "text-body"
defp grade_label(nil, _result), do: nil
defp grade_label(:optimal, _result), do: "Optimal move"
@@ -52,11 +52,11 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndex do
{round(endgame.rating)}
</td>
<td>
<span :for={theme <- endgame.themes} class="badge badge-sm">
<.badge :for={theme <- endgame.themes} size="sm">
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>
{theme.name}
</button>
</span>
</.badge>
<span :if={endgame.themes == []} class="text-base-content/50">None</span>
</td>
<td class="w-0 font-semibold">
+3 -3
View File
@@ -15,7 +15,7 @@ defmodule ChesstrainerWeb.UserLive.Login do
<% else %>
Don't have an account? <.link
navigate={~p"/users/register"}
class="font-semibold text-brand hover:underline"
class="font-semibold text-primary hover:underline"
phx-no-format
>Sign up</.link> for an account now.
<% end %>
@@ -47,10 +47,10 @@ defmodule ChesstrainerWeb.UserLive.Login do
autocomplete="current-password"
spellcheck="false"
/>
<.button class="btn btn-primary w-full" name={@form[:remember_me].name} value="true">
<.button variant="primary" class="w-full" name={@form[:remember_me].name} value="true">
Log in and stay logged in <span aria-hidden="true">→</span>
</.button>
<.button class="btn btn-primary btn-soft w-full mt-2">
<.button class="w-full mt-2">
Log in only this time
</.button>
</.form>
@@ -14,7 +14,7 @@ defmodule ChesstrainerWeb.UserLive.Registration do
Register for an account
<:subtitle>
Already registered?
<.link navigate={~p"/users/log-in"} class="font-semibold text-brand hover:underline">
<.link navigate={~p"/users/log-in"} class="font-semibold text-primary hover:underline">
Log in
</.link>
to your account now.
@@ -57,7 +57,7 @@ defmodule ChesstrainerWeb.UserLive.Registration do
required
/>
<.button phx-disable-with="Creating account..." class="btn btn-primary w-full">
<.button phx-disable-with="Creating account..." variant="primary" class="w-full">
Create an account
</.button>
</.form>
@@ -28,7 +28,7 @@ defmodule ChesstrainerWeb.UserLive.Settings do
<.button variant="primary" phx-disable-with="Changing...">Change Email</.button>
</.form>
<div class="divider" />
<hr class="my-6 border-base-200" />
<.form
for={@password_form}
@@ -66,7 +66,7 @@ defmodule ChesstrainerWeb.UserLive.Settings do
</.button>
</.form>
<div class="divider" />
<hr class="my-6 border-base-200" />
<section id="delete_account" class="space-y-4">
<.header>
@@ -79,15 +79,14 @@ defmodule ChesstrainerWeb.UserLive.Settings do
Nothing can be recovered.
</p>
<button
<.button
id="delete_account_button"
type="button"
class="btn btn-error"
variant="danger"
phx-click="delete_account"
data-confirm="This permanently deletes your account and all of your data. Nothing can be recovered. Are you sure?"
>
Delete my account
</button>
</.button>
</section>
</Layouts.app>
"""