mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Compare commits
4
Commits
fd6277ef92
...
c95173cda8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c95173cda8
|
||
|
|
e89df68e7d
|
||
|
|
6b0e0ed352
|
||
|
|
93806b9ab2 |
+16
-2
@@ -12,9 +12,15 @@ _Avoid_: Position, puzzle
|
|||||||
|
|
||||||
**Puzzle**:
|
**Puzzle**:
|
||||||
A playable challenge derived from an endgame: play the winning (or drawing)
|
A playable challenge derived from an endgame: play the winning (or drawing)
|
||||||
side correctly against tablebase-optimal defence.
|
side correctly against tablebase-optimal defence. Each endgame currently
|
||||||
|
yields one puzzle.
|
||||||
_Avoid_: Endgame (the stored record), exercise
|
_Avoid_: Endgame (the stored record), exercise
|
||||||
|
|
||||||
|
**Daily puzzle**:
|
||||||
|
The one endgame assigned to a UTC date and shared by every user; the
|
||||||
|
assignment is persisted so it stays stable for that day.
|
||||||
|
_Avoid_: Random puzzle, featured puzzle
|
||||||
|
|
||||||
**Attempt**:
|
**Attempt**:
|
||||||
A recorded playthrough of a puzzle by a user, ending solved or failed; a
|
A recorded playthrough of a puzzle by a user, ending solved or failed; a
|
||||||
per-user record, distinct from an endgame's global attempt and solve counts.
|
per-user record, distinct from an endgame's global attempt and solve counts.
|
||||||
@@ -23,7 +29,15 @@ _Avoid_: Run, session, game
|
|||||||
**Theme**:
|
**Theme**:
|
||||||
A label describing an endgame's technique or goal, such as "mate in 2", "Lucena" or
|
A label describing an endgame's technique or goal, such as "mate in 2", "Lucena" or
|
||||||
"opposition"; an endgame can carry several.
|
"opposition"; an endgame can carry several.
|
||||||
_Avoid_: Tag, label, category
|
_Avoid_: Tag, label, category, UI theme, colour mode
|
||||||
|
|
||||||
|
## Interface
|
||||||
|
|
||||||
|
**Colour mode**:
|
||||||
|
A user's display preference for the interface — `system`, `light` or `dark` — where
|
||||||
|
`system` follows the operating system setting. It is a per-browser preference,
|
||||||
|
independent of any user account.
|
||||||
|
_Avoid_: Theme, colour scheme, display theme
|
||||||
|
|
||||||
**Key**:
|
**Key**:
|
||||||
The canonical material signature of an endgame's starting position — which
|
The canonical material signature of an endgame's starting position — which
|
||||||
|
|||||||
@@ -5,18 +5,25 @@ Granular tasks and operational scratchpad for active development.
|
|||||||
---
|
---
|
||||||
|
|
||||||
## In Progress 🟡
|
## In Progress 🟡
|
||||||
- [ ] Basic design and colour scheme
|
- [x] Basic design and colour scheme
|
||||||
|
- [x] Apply design to the rest of the site
|
||||||
|
- [x] Create reusable components such as button
|
||||||
|
- [x] Organise nav bar
|
||||||
- [ ] Display puzzles and move to next
|
- [ ] Display puzzles and move to next
|
||||||
|
- [x] Create footer
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Next Up (Sprint Backlog) 🟢
|
## Next Up (Sprint Backlog) 🟢
|
||||||
- [ ] Forgot password
|
- [ ] Forgot password
|
||||||
- [ ] Anonymous trial of 10 puzzles without logging in
|
- [ ] Anonymous trial of 10 puzzles without logging in
|
||||||
|
- [x] Light / Dark mode
|
||||||
|
- [ ] WCAG compliance
|
||||||
|
- [x] Self host font - google fonts not gdpr compliant
|
||||||
---
|
---
|
||||||
|
|
||||||
## Tech Debt & Refactoring 🧹
|
## Tech Debt & Refactoring 🧹
|
||||||
|
- [ ] Split CSS into modules (ongoing)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
.bg-boardwhite {
|
|
||||||
background-color: #f2f5f3; /* light square */
|
|
||||||
}
|
|
||||||
|
|
||||||
.bg-boardblack {
|
|
||||||
background-color: #71828f; /* dark square */
|
|
||||||
}
|
|
||||||
+50
-98
@@ -4,116 +4,68 @@
|
|||||||
@import "tailwindcss" source(none);
|
@import "tailwindcss" source(none);
|
||||||
@import "phoenix-colocated/chesstrainer/colocated.css";
|
@import "phoenix-colocated/chesstrainer/colocated.css";
|
||||||
|
|
||||||
|
/* Chessground imports */
|
||||||
@import "../node_modules/chessground/assets/chessground.base.css";
|
@import "../node_modules/chessground/assets/chessground.base.css";
|
||||||
@import "../node_modules/chessground/assets/chessground.brown.css";
|
@import "../node_modules/chessground/assets/chessground.brown.css";
|
||||||
@import "../node_modules/chessground/assets/chessground.cburnett.css";
|
@import "../node_modules/chessground/assets/chessground.cburnett.css";
|
||||||
|
|
||||||
@import "./_board.css";
|
@import "./helpers/_variables.css";
|
||||||
@import "./_promotion.css";
|
@import "./base/_theme.css";
|
||||||
|
@import "./base/_globals.css";
|
||||||
|
@import "./base/_typography.css";
|
||||||
|
@import "./layouts/_nav.css";
|
||||||
|
@import "./layouts/_footer.css";
|
||||||
|
@import "./layouts/_hero.css";
|
||||||
|
@import "./layouts/_section.css";
|
||||||
|
@import "./components/_icon.css";
|
||||||
|
@import "./components/_button.css";
|
||||||
|
@import "./components/_learning-strip.css";
|
||||||
|
@import "./components/_board.css";
|
||||||
|
@import "./components/_promotion.css";
|
||||||
|
|
||||||
@source "../css";
|
@source "../css";
|
||||||
@source "../js";
|
@source "../js";
|
||||||
@source "../../lib/chesstrainer_web";
|
@source "../../lib/chesstrainer_web";
|
||||||
/* Required for Tailwind to automatically pick up changes in colocated CSS files in dev */
|
|
||||||
@source "../../_build/dev/phoenix-colocated/chesstrainer/*/";
|
@source "../../_build/dev/phoenix-colocated/chesstrainer/*/";
|
||||||
|
|
||||||
/* A Tailwind plugin that makes "hero-#{ICON}" classes available.
|
/* A Tailwind plugin that makes "hero-#{ICON}" classes available.
|
||||||
The heroicons installation itself is managed by your mix.exs */
|
The heroicons installation itself is managed by your mix.exs */
|
||||||
@plugin "../vendor/heroicons";
|
@plugin "../vendor/heroicons";
|
||||||
|
|
||||||
/* daisyUI Tailwind Plugin. You can update this file by fetching the latest version with:
|
.rating-note { display: flex; align-items: center; gap: 11px; color: var(--color-muted); font-size: 11px; line-height: 1.3; }
|
||||||
curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js
|
.rating-note strong { display: block; color: var(--color-body); font-size: 12px; }
|
||||||
Make sure to look at the daisyUI changelog: https://daisyui.com/docs/changelog/ */
|
.avatar-stack { display: flex; }
|
||||||
@plugin "../vendor/daisyui" {
|
.avatar-stack i { width: 29px; height: 29px; display: grid; place-items: center; margin-left: -7px; border: 2px solid var(--color-canvas); border-radius: 50%; background: var(--color-mint-chip); color: var(--color-body); font-style: normal; }
|
||||||
themes: false;
|
.avatar-stack i:first-child { margin-left: 0; background: var(--color-coral-control); color: #fff; }
|
||||||
|
.avatar-stack i:last-child { background: var(--color-deep); color: var(--color-on-deep); }
|
||||||
|
.puzzle-section { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 110px 0 125px; }
|
||||||
|
.puzzle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
|
||||||
|
.puzzle-card { display: block; position: relative; min-height: 285px; padding: 25px; text-align: left; text-decoration: none; color: inherit; cursor: pointer; border: 1px solid var(--color-hairline); border-radius: 12px; background: rgba(255,255,255,.28); overflow: hidden; transition: transform .25s, background .25s, box-shadow .25s; }
|
||||||
|
.puzzle-card:hover, .puzzle-card.active { transform: translateY(-5px); background: var(--color-canvas-raised); box-shadow: 0 18px 36px rgba(23,53,45,.08); }
|
||||||
|
.puzzle-card.active { border-color: var(--color-success-text); }
|
||||||
|
.card-number { color: var(--color-muted); font-size: 10px; font-weight: 700; letter-spacing: .12em; }
|
||||||
|
.mini-piece { display: block; margin: 27px 0 22px; font-family: Georgia, serif; color: var(--color-body); font-size: 57px; line-height: 1; }
|
||||||
|
.difficulty { display: block; margin-bottom: 8px; color: var(--color-coral-text); font-size: 9px; text-transform: uppercase; font-weight: 700; letter-spacing: .12em; }
|
||||||
|
.puzzle-card strong { display: block; font-family: 'DM Serif Display', serif; font-size: 24px; font-weight: 400; }
|
||||||
|
.puzzle-card small { color: var(--color-muted); font-size: 11px; }
|
||||||
|
.card-arrow { position: absolute; right: 22px; bottom: 23px; display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--color-hairline); border-radius: 50%; transition: background .2s, color .2s; }
|
||||||
|
.puzzle-card:hover .card-arrow, .puzzle-card.active .card-arrow { background: var(--color-coral-control); color: white; border-color: var(--color-coral-control); }
|
||||||
|
.progress-banner { width: min(1180px, calc(100% - 48px)); margin: 0 auto 60px; padding: 70px 76px; display: flex; justify-content: space-between; align-items: end; border-radius: 16px; color: white; background: var(--color-coral-control); }
|
||||||
|
.progress-banner .section-kicker { color: var(--color-on-accent-muted); }
|
||||||
|
|
||||||
|
|
||||||
|
/* Dark mode needs a few tuned surfaces: tints and shadows are meaningless when
|
||||||
|
the canvas flips, and they are not worth a role token each. */
|
||||||
|
html[data-theme="dark"] .puzzle-card { background: rgba(233, 239, 233, .045); }
|
||||||
|
html[data-theme="dark"] .puzzle-card:hover,
|
||||||
|
html[data-theme="dark"] .puzzle-card.active { box-shadow: 0 18px 36px rgba(0, 0, 0, .35); }
|
||||||
|
html[data-theme="dark"] .board-shell { box-shadow: 0 26px 65px rgba(0, 0, 0, .55); }
|
||||||
|
html[data-theme="dark"] .primary-button { box-shadow: 0 10px 28px rgba(0, 0, 0, .35); }
|
||||||
|
html[data-theme="dark"] .learning-strip { box-shadow: inset 0 1px 0 var(--color-hairline); }
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.puzzle-section { width: calc(100% - 36px); padding: 80px 0; }
|
||||||
|
.puzzle-grid { grid-template-columns: 1fr; }
|
||||||
|
.puzzle-card { min-height: 255px; }
|
||||||
|
.progress-banner { width: calc(100% - 36px); padding: 48px 28px; flex-direction: column; align-items: flex-start; gap: 34px; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* daisyUI theme plugin. You can update this file by fetching the latest version with:
|
|
||||||
curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui-theme.js
|
|
||||||
We ship with two themes, a light one inspired on Phoenix colors and a dark one inspired
|
|
||||||
on Elixir colors. Build your own at: https://daisyui.com/theme-generator/ */
|
|
||||||
@plugin "../vendor/daisyui-theme" {
|
|
||||||
name: "dark";
|
|
||||||
default: false;
|
|
||||||
prefersdark: true;
|
|
||||||
color-scheme: "dark";
|
|
||||||
--color-base-100: oklch(30.33% 0.016 252.42);
|
|
||||||
--color-base-200: oklch(25.26% 0.014 253.1);
|
|
||||||
--color-base-300: oklch(20.15% 0.012 254.09);
|
|
||||||
--color-base-content: oklch(97.807% 0.029 256.847);
|
|
||||||
--color-primary: oklch(58% 0.233 277.117);
|
|
||||||
--color-primary-content: oklch(96% 0.018 272.314);
|
|
||||||
--color-secondary: oklch(58% 0.233 277.117);
|
|
||||||
--color-secondary-content: oklch(96% 0.018 272.314);
|
|
||||||
--color-accent: oklch(60% 0.25 292.717);
|
|
||||||
--color-accent-content: oklch(96% 0.016 293.756);
|
|
||||||
--color-neutral: oklch(37% 0.044 257.287);
|
|
||||||
--color-neutral-content: oklch(98% 0.003 247.858);
|
|
||||||
--color-info: oklch(58% 0.158 241.966);
|
|
||||||
--color-info-content: oklch(97% 0.013 236.62);
|
|
||||||
--color-success: oklch(60% 0.118 184.704);
|
|
||||||
--color-success-content: oklch(98% 0.014 180.72);
|
|
||||||
--color-warning: oklch(66% 0.179 58.318);
|
|
||||||
--color-warning-content: oklch(98% 0.022 95.277);
|
|
||||||
--color-error: oklch(58% 0.253 17.585);
|
|
||||||
--color-error-content: oklch(96% 0.015 12.422);
|
|
||||||
--radius-selector: 0.25rem;
|
|
||||||
--radius-field: 0.25rem;
|
|
||||||
--radius-box: 0.5rem;
|
|
||||||
--size-selector: 0.21875rem;
|
|
||||||
--size-field: 0.21875rem;
|
|
||||||
--border: 1.5px;
|
|
||||||
--depth: 1;
|
|
||||||
--noise: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@plugin "../vendor/daisyui-theme" {
|
|
||||||
name: "light";
|
|
||||||
default: true;
|
|
||||||
prefersdark: false;
|
|
||||||
color-scheme: "light";
|
|
||||||
--color-base-100: oklch(98% 0 0);
|
|
||||||
--color-base-200: oklch(96% 0.001 286.375);
|
|
||||||
--color-base-300: oklch(92% 0.004 286.32);
|
|
||||||
--color-base-content: oklch(21% 0.006 285.885);
|
|
||||||
--color-primary: oklch(70% 0.213 47.604);
|
|
||||||
--color-primary-content: oklch(98% 0.016 73.684);
|
|
||||||
--color-secondary: oklch(55% 0.027 264.364);
|
|
||||||
--color-secondary-content: oklch(98% 0.002 247.839);
|
|
||||||
--color-accent: oklch(0% 0 0);
|
|
||||||
--color-accent-content: oklch(100% 0 0);
|
|
||||||
--color-neutral: oklch(44% 0.017 285.786);
|
|
||||||
--color-neutral-content: oklch(98% 0 0);
|
|
||||||
--color-info: oklch(62% 0.214 259.815);
|
|
||||||
--color-info-content: oklch(97% 0.014 254.604);
|
|
||||||
--color-success: oklch(70% 0.14 182.503);
|
|
||||||
--color-success-content: oklch(98% 0.014 180.72);
|
|
||||||
--color-warning: oklch(66% 0.179 58.318);
|
|
||||||
--color-warning-content: oklch(98% 0.022 95.277);
|
|
||||||
--color-error: oklch(58% 0.253 17.585);
|
|
||||||
--color-error-content: oklch(96% 0.015 12.422);
|
|
||||||
--radius-selector: 0.25rem;
|
|
||||||
--radius-field: 0.25rem;
|
|
||||||
--radius-box: 0.5rem;
|
|
||||||
--size-selector: 0.21875rem;
|
|
||||||
--size-field: 0.21875rem;
|
|
||||||
--border: 1.5px;
|
|
||||||
--depth: 1;
|
|
||||||
--noise: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add variants based on LiveView classes */
|
|
||||||
@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
|
|
||||||
@custom-variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &);
|
|
||||||
@custom-variant phx-change-loading (.phx-change-loading&, .phx-change-loading &);
|
|
||||||
|
|
||||||
/* Use the data attribute for dark mode */
|
|
||||||
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
|
||||||
|
|
||||||
/* Make LiveView wrapper divs transparent for layout */
|
|
||||||
[data-phx-session],
|
|
||||||
[data-phx-teleported-src] {
|
|
||||||
display: contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This file is for your main application CSS */
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
html { scroll-behavior: smooth; }
|
||||||
|
body {
|
||||||
|
min-width: 320px;
|
||||||
|
background: var(--color-canvas);
|
||||||
|
color: var(--color-body);
|
||||||
|
font-family: 'DM Sans', sans-serif;
|
||||||
|
}
|
||||||
|
button, a { -webkit-tap-highlight-color: transparent; }
|
||||||
|
button { cursor: pointer; }
|
||||||
|
}
|
||||||
|
|
||||||
|
main { overflow: hidden; }
|
||||||
|
|
||||||
|
/* LiveView */
|
||||||
|
@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
|
||||||
|
@custom-variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &);
|
||||||
|
@custom-variant phx-change-loading (.phx-change-loading&, .phx-change-loading &);
|
||||||
|
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
||||||
|
|
||||||
|
/* Make LiveView wrapper divs transparent for layout */
|
||||||
|
[data-phx-session],
|
||||||
|
[data-phx-teleported-src] {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
@theme static {
|
||||||
|
/* Roles — light mode reads from the palette. */
|
||||||
|
--color-canvas: var(--paper);
|
||||||
|
--color-canvas-raised: var(--cream);
|
||||||
|
--color-body: var(--ink);
|
||||||
|
--color-muted: var(--ink-soft);
|
||||||
|
--color-hairline: var(--line);
|
||||||
|
--color-deep: var(--ink);
|
||||||
|
--color-on-deep: var(--paper);
|
||||||
|
--color-coral: var(--coral);
|
||||||
|
--color-coral-control: var(--coral);
|
||||||
|
--color-coral-control-hover: var(--coral-dark);
|
||||||
|
--color-coral-text: var(--coral-dark);
|
||||||
|
--color-success-text: var(--mint-deep);
|
||||||
|
--color-mint-chip: var(--mint);
|
||||||
|
--color-on-accent-muted: #5f2c23;
|
||||||
|
|
||||||
|
/* Content colours — identical in every colour mode. */
|
||||||
|
--color-board-light: #e9e1cc;
|
||||||
|
--color-board-dark: #81a996;
|
||||||
|
--color-piece-light: #fffdf5;
|
||||||
|
--color-piece-outline: #17352d;
|
||||||
|
--color-on-deep-muted: #c8d6d1;
|
||||||
|
--color-on-deep-faint: #a9beb6;
|
||||||
|
|
||||||
|
/* Promotion picker. */
|
||||||
|
--color-promotion-surface: #ffffff;
|
||||||
|
--color-promotion-tile: #fafafa;
|
||||||
|
--color-promotion-tile-hover: #fff1ec;
|
||||||
|
--color-promotion-selected: var(--coral);
|
||||||
|
|
||||||
|
/* Phoenix semantic tokens, retuned to the brand. Utilities such as
|
||||||
|
`bg-base-200` and `text-base-content` resolve through these. */
|
||||||
|
--color-base-100: #fffcf4;
|
||||||
|
--color-base-200: #f4f0e6;
|
||||||
|
--color-base-300: #e7e1d3;
|
||||||
|
--color-base-content: #17352d;
|
||||||
|
--color-primary: #c74c33;
|
||||||
|
--color-primary-content: #ffffff;
|
||||||
|
--color-secondary: #17352d;
|
||||||
|
--color-secondary-content: #f4f0e6;
|
||||||
|
--color-accent: #3f6d5a;
|
||||||
|
--color-accent-content: #ffffff;
|
||||||
|
--color-neutral: #587068;
|
||||||
|
--color-neutral-content: #f4f0e6;
|
||||||
|
--color-info: oklch(62% 0.214 259.815);
|
||||||
|
--color-info-content: oklch(97% 0.014 254.604);
|
||||||
|
--color-success: oklch(70% 0.14 182.503);
|
||||||
|
--color-success-content: oklch(98% 0.014 180.72);
|
||||||
|
--color-warning: oklch(66% 0.179 58.318);
|
||||||
|
--color-warning-content: oklch(98% 0.022 95.277);
|
||||||
|
--color-error: oklch(58% 0.253 17.585);
|
||||||
|
--color-error-content: oklch(96% 0.015 12.422);
|
||||||
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] {
|
||||||
|
color-scheme: dark;
|
||||||
|
|
||||||
|
--color-canvas: #0f1714;
|
||||||
|
--color-canvas-raised: #1b2822;
|
||||||
|
--color-body: #e9efe9;
|
||||||
|
--color-muted: #9ab0a5;
|
||||||
|
--color-hairline: rgba(233, 239, 233, 0.14);
|
||||||
|
--color-deep: #1d3c33;
|
||||||
|
--color-on-deep: #f4f0e6;
|
||||||
|
--color-coral: #f2816b;
|
||||||
|
--color-coral-control: #c74c33;
|
||||||
|
--color-coral-control-hover: #b8432c;
|
||||||
|
--color-coral-text: #ff9c85;
|
||||||
|
--color-success-text: #8fd3b5;
|
||||||
|
--color-mint-chip: #24403a;
|
||||||
|
--color-on-accent-muted: rgba(255, 255, 255, 0.97);
|
||||||
|
--color-promotion-surface: #1b2822;
|
||||||
|
--color-promotion-tile: #233029;
|
||||||
|
--color-promotion-tile-hover: #2c3d35;
|
||||||
|
--color-promotion-selected: #ff9c85;
|
||||||
|
|
||||||
|
--color-base-100: #1b2822;
|
||||||
|
--color-base-200: #141f1a;
|
||||||
|
--color-base-300: #0f1714;
|
||||||
|
--color-base-content: #e9efe9;
|
||||||
|
--color-primary: #c74c33;
|
||||||
|
--color-primary-content: #ffffff;
|
||||||
|
--color-secondary: #1d3c33;
|
||||||
|
--color-secondary-content: #f4f0e6;
|
||||||
|
--color-accent: #8fd3b5;
|
||||||
|
--color-accent-content: #0f1714;
|
||||||
|
--color-neutral: #2b3a33;
|
||||||
|
--color-neutral-content: #e9efe9;
|
||||||
|
--color-info: oklch(70% 0.14 240);
|
||||||
|
--color-info-content: oklch(15% 0.02 240);
|
||||||
|
--color-success: oklch(72% 0.13 165);
|
||||||
|
--color-success-content: oklch(15% 0.02 165);
|
||||||
|
--color-warning: oklch(78% 0.15 75);
|
||||||
|
--color-warning-content: oklch(20% 0.03 75);
|
||||||
|
--color-error: oklch(66% 0.19 22);
|
||||||
|
--color-error-content: oklch(15% 0.02 22);
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: "DM Sans";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 100 1000;
|
||||||
|
font-display: swap;
|
||||||
|
src: url("/fonts/dm-sans-variable.woff2") format("woff2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: "DM Sans";
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: swap;
|
||||||
|
src: url("/fonts/dm-sans-italic.woff2") format("woff2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: "DM Serif Display";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: swap;
|
||||||
|
src: url("/fonts/dm-serif-display.woff2") format("woff2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: "DM Serif Display";
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: swap;
|
||||||
|
src: url("/fonts/dm-serif-display-italic.woff2") format("woff2");
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2 { font-family: 'DM Serif Display', serif; font-weight: 400; letter-spacing: -.035em; }
|
||||||
|
h1 { max-width: 590px; font-size: clamp(56px, 6vw, 87px); line-height: .93; }
|
||||||
|
h1 em { color: var(--color-coral); font-weight: 400; }
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
h1 { font-size: clamp(51px, 15vw, 68px); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* Hero Chessboard */
|
||||||
|
.board-shell { position: relative; z-index: 2; width: min(458px, 85vw); padding: 18px; border-radius: 12px; background: var(--color-canvas-raised); box-shadow: 0 26px 65px rgba(23, 53, 45, .25); transform: rotate(1.5deg); }
|
||||||
|
.board-topline, .board-caption { display: flex; align-items: center; justify-content: space-between; }
|
||||||
|
.board-topline { padding: 1px 1px 13px; }
|
||||||
|
.board-stage { position: relative; min-height: 580px; display: grid; place-items: center; }
|
||||||
|
.chessboard { aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr); overflow: hidden; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.05); }
|
||||||
|
.player { display: flex; align-items: center; gap: 9px; }
|
||||||
|
.player-piece { display: grid; place-items: center; width: 31px; height: 31px; background: var(--color-deep); border-radius: 50%; color: var(--color-on-deep); font-size: 20px; }
|
||||||
|
.player span:last-child { display: flex; flex-direction: column; line-height: 1.05; }
|
||||||
|
.player small { color: var(--color-muted); font-size: 8px; text-transform: uppercase; letter-spacing: .1em; }
|
||||||
|
.player strong { font-size: 12px; }
|
||||||
|
.square { position: relative; display: grid; place-items: center; aspect-ratio: 1; border: 0; }
|
||||||
|
.square.light { background: var(--color-board-light); }
|
||||||
|
.square.dark { background: var(--color-board-dark); }
|
||||||
|
.piece { position: relative; z-index: 2; font-family: Georgia, serif; font-size: clamp(25px, 4vw, 42px); line-height: 1; transform: translateY(-1px); }
|
||||||
|
.white-piece { color: var(--color-piece-light); text-shadow: 0 2px 0 var(--color-piece-outline), 1px 0 0 var(--color-piece-outline), -1px 0 0 var(--color-piece-outline), 0 -1px 0 var(--color-piece-outline); }
|
||||||
|
.black-piece { color: var(--color-piece-outline); text-shadow: 0 1px 0 rgba(255,255,255,.25); }
|
||||||
|
.rank, .file { position: absolute; z-index: 3; color: rgba(23,53,45,.65); font-size: 7px; font-weight: 700; }
|
||||||
|
.rank { top: 3px; left: 4px; }
|
||||||
|
.file { right: 4px; bottom: 2px; }
|
||||||
|
.dark .rank, .dark .file { color: rgba(255,255,255,.65); }
|
||||||
|
.board-caption { padding: 14px 2px 0; }
|
||||||
|
.board-caption div { display: flex; flex-direction: column; }
|
||||||
|
.board-caption span { color: var(--color-muted); font-size: 9px; text-transform: uppercase; letter-spacing: .1em; }
|
||||||
|
.board-caption strong { font-size: 13px; }
|
||||||
|
.board-caption button { color: var(--color-coral-text); font-size: 11px; font-weight: 700; }
|
||||||
|
.board-themes { color: var(--color-coral-text); font-size: 8px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.board-stage { min-height: 620px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.board-stage { min-height: 500px; }
|
||||||
|
.board-shell { width: min(390px, 92vw); padding: 12px; }
|
||||||
|
.piece { font-size: clamp(24px, 9vw, 38px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Admin Chessboard */
|
||||||
|
.bg-boardwhite { background-color: #f2f5f3; /* light square */ }
|
||||||
|
.bg-boardblack { background-color: #71828f; /* dark square */ }
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
.primary-button { padding: 16px 23px; background: var(--color-coral-control); color: #fff; box-shadow: 0 10px 28px rgba(217, 93, 72, .21); }
|
||||||
|
.primary-button:hover { background: var(--color-coral-control-hover); }
|
||||||
|
.light-button { padding: 15px 22px; background: var(--color-canvas-raised); color: var(--color-body); white-space: nowrap; }
|
||||||
|
.menu-button { display: none; }
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.menu-button { display: flex; width: 38px; height: 38px; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
|
||||||
|
.menu-button span { width: 19px; height: 1.5px; background: var(--color-body); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.eyebrow { display: flex; align-items: center; gap: 9px; margin-bottom: 27px; color: var(--color-coral-text); text-transform: uppercase; letter-spacing: .13em; font-size: 12px; font-weight: 700; }
|
||||||
|
.eyebrow svg { width: 20px; height: 20px; }
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
.learning-strip {
|
||||||
|
padding: 27px max(24px, calc((100% - 1180px)/2));
|
||||||
|
display: grid; grid-template-columns: 1.5fr repeat(3, 1fr); align-items: center; background: var(--color-deep); color: var(--color-on-deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
.learning-strip > p { max-width: 260px; color: var(--color-on-deep-muted); font-family: 'DM Serif Display', serif; font-size: 19px; line-height: 1.25; }
|
||||||
|
|
||||||
|
.stat { padding-left: 34px; border-left: 1px solid rgba(255,255,255,.17); }
|
||||||
|
.stat strong { display: block; font-family: 'DM Serif Display', serif; font-size: 28px; font-weight: 400; }
|
||||||
|
.stat span { color: var(--color-on-deep-faint); font-size: 10px; text-transform: uppercase; letter-spacing: .09em; }
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.learning-strip { grid-template-columns: 1fr repeat(3, .7fr); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.learning-strip { padding: 38px 24px; grid-template-columns: 1fr 1fr; gap: 30px 10px; }
|
||||||
|
.learning-strip > p { grid-column: 1 / -1; }
|
||||||
|
.stat { padding-left: 18px; }
|
||||||
|
.stat:last-child { grid-column: 1 / -1; }
|
||||||
|
}
|
||||||
@@ -13,19 +13,23 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
background: white;
|
background: var(--color-promotion-surface);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] .promotion-overlay {
|
||||||
|
background: rgba(0, 0, 0, 0.68);
|
||||||
|
}
|
||||||
|
|
||||||
.promotion-piece {
|
.promotion-piece {
|
||||||
width: 80px;
|
width: 80px;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: 2px solid transparent;
|
border: 2px solid transparent;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background-color: #fafafa;
|
background-color: var(--color-promotion-tile);
|
||||||
background-size: 80% 80%;
|
background-size: 80% 80%;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
@@ -33,8 +37,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.promotion-piece:hover {
|
.promotion-piece:hover {
|
||||||
background-color: #eff6ff;
|
background-color: var(--color-promotion-tile-hover);
|
||||||
border-color: #3b82f6;
|
border-color: var(--color-promotion-selected);
|
||||||
transform: scale(1.08);
|
transform: scale(1.08);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
:root {
|
||||||
|
/* Raw brand palette. */
|
||||||
|
--ink: #17352d;
|
||||||
|
--ink-soft: #587068;
|
||||||
|
--paper: #f4f0e6;
|
||||||
|
--cream: #fffcf4;
|
||||||
|
--mint: #b9d7c9;
|
||||||
|
--mint-deep: #8bb9a8;
|
||||||
|
--coral: #ef755d;
|
||||||
|
--coral-dark: #d95d48;
|
||||||
|
--line: rgba(23, 53, 45, 0.15);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
.site-footer {
|
||||||
|
width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 44px 0;
|
||||||
|
display: flex; align-items: center; justify-content: space-between; gap: 30px;
|
||||||
|
border-top: 1px solid var(--color-hairline);
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-brand { display: flex; flex-direction: column; gap: 12px; }
|
||||||
|
.footer-brand p { color: var(--color-muted); font-size: 13px; }
|
||||||
|
.footer-links { display: flex; gap: 26px; font-size: 14px; font-weight: 600; }
|
||||||
|
.footer-links a { transition: opacity .2s; }
|
||||||
|
.footer-links a:hover { opacity: .55; }
|
||||||
|
.site-footer > small { color: var(--color-muted); font-size: 11px; }
|
||||||
|
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.site-footer { width: calc(100% - 36px); flex-direction: column; align-items: flex-start; gap: 24px; }
|
||||||
|
.footer-links { flex-wrap: wrap; gap: 16px 22px; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
.hero {
|
||||||
|
width: min(1180px, calc(100% - 48px)); min-height: 650px; margin: 0 auto;
|
||||||
|
display: grid; grid-template-columns: .91fr 1.09fr; align-items: center; gap: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-copy { position: relative; z-index: 2; padding: 74px 0 92px; }
|
||||||
|
.hero-copy > p { max-width: 480px; margin-top: 29px; color: var(--color-muted); font-size: 17px; line-height: 1.65; }
|
||||||
|
.hero-actions { display: flex; align-items: center; gap: 25px; margin-top: 35px; }
|
||||||
|
|
||||||
|
.coral-orbit, .mint-orbit { position: absolute; border-radius: 50%; }
|
||||||
|
.coral-orbit { width: 460px; height: 460px; right: -34px; top: 46px; background: var(--color-coral); }
|
||||||
|
.mint-orbit { width: 230px; height: 230px; left: 14px; bottom: 28px; background: var(--color-mint-chip); }
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.hero { grid-template-columns: 1fr; gap: 0; }
|
||||||
|
.hero-copy { padding-bottom: 30px; }
|
||||||
|
.hero-copy > p { max-width: 560px; }
|
||||||
|
.coral-orbit { right: 6%; }
|
||||||
|
.mint-orbit { left: 10%; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.hero { width: calc(100% - 36px); }
|
||||||
|
.hero-copy { padding: 65px 0 24px; }
|
||||||
|
.hero-copy > p { font-size: 15px; }
|
||||||
|
.coral-orbit { width: 340px; height: 340px; right: -28%; top: 65px; }
|
||||||
|
.mint-orbit { width: 170px; height: 170px; left: -8%; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
.nav-wrap {
|
||||||
|
width: min(1180px, calc(100% - 48px));
|
||||||
|
height: 92px;
|
||||||
|
margin: 0 auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
border-bottom: 1px solid var(--color-hairline);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-right { display: flex; align-items: center; gap: 22px; }
|
||||||
|
|
||||||
|
.nav-links { display: flex; align-items: center; gap: 34px; font-size: 14px; font-weight: 600; }
|
||||||
|
.nav-links a { transition: opacity .2s; }
|
||||||
|
.nav-links a:hover { opacity: .55; }
|
||||||
|
.nav-links a.nav-cta:hover { opacity: 1; }
|
||||||
|
.nav-user { color: var(--color-muted); font-weight: 500; }
|
||||||
|
.nav-cta, .primary-button, .light-button {
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; gap: 13px;
|
||||||
|
border-radius: 999px; font-weight: 600; transition: transform .2s, background .2s;
|
||||||
|
}
|
||||||
|
.nav-cta { padding: 12px 19px; color: var(--color-on-deep); background: var(--color-deep); }
|
||||||
|
.nav-cta svg, .primary-button svg, .light-button svg, .card-arrow svg { width: 18px; height: 18px; }
|
||||||
|
.nav-cta:hover, .primary-button:hover, .light-button:hover { transform: translateY(-2px); }
|
||||||
|
|
||||||
|
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; letter-spacing: .18em; }
|
||||||
|
.brand-mark { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 50%; background: var(--color-deep); color: var(--color-on-deep); font-size: 21px; letter-spacing: 0; }
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.nav-links { gap: 20px; }
|
||||||
|
.nav-right { gap: 16px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.nav-wrap { width: calc(100% - 36px); height: 74px; position: relative; z-index: 10; }
|
||||||
|
.nav-right { gap: 12px; }
|
||||||
|
.nav-links.open { display: flex; }
|
||||||
|
.nav-cta { width: 100%; }
|
||||||
|
.nav-links { display: none; position: absolute; top: 65px; left: 0; right: 0; padding: 24px; flex-direction: column; align-items: stretch; gap: 22px; border-radius: 10px; background: var(--color-canvas-raised); box-shadow: 0 18px 40px rgba(23,53,45,.15); }
|
||||||
|
html[data-theme="dark"] .nav-links { box-shadow: 0 18px 40px rgba(0, 0, 0, .45); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
.section-heading { display: grid; grid-template-columns: 1fr .65fr; align-items: end; margin-bottom: 46px; }
|
||||||
|
.section-kicker { display: block; margin-bottom: 14px; color: var(--color-coral-text); text-transform: uppercase; letter-spacing: .13em; font-size: 11px; font-weight: 700; }
|
||||||
|
.section-heading h2, .progress-banner h2 { font-size: clamp(43px, 5vw, 65px); line-height: .96; }
|
||||||
|
.section-heading > p { max-width: 390px; color: var(--color-muted); font-size: 14px; line-height: 1.7; }
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.section-heading { grid-template-columns: 1fr .8fr; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.section-heading { grid-template-columns: 1fr; gap: 25px; }
|
||||||
|
}
|
||||||
+4
-2
@@ -19,18 +19,20 @@
|
|||||||
|
|
||||||
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
|
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
|
||||||
import "phoenix_html";
|
import "phoenix_html";
|
||||||
|
// Plain-DOM mobile navigation (works on controller and LiveView pages).
|
||||||
|
import "./nav";
|
||||||
// Establish Phoenix Socket and LiveView configuration.
|
// Establish Phoenix Socket and LiveView configuration.
|
||||||
import { Socket } from "phoenix";
|
import { Socket } from "phoenix";
|
||||||
import { LiveSocket } from "phoenix_live_view";
|
import { LiveSocket } from "phoenix_live_view";
|
||||||
import { hooks as colocatedHooks } from "phoenix-colocated/chesstrainer";
|
import { hooks as colocatedHooks } from "phoenix-colocated/chesstrainer";
|
||||||
import topbar from "../vendor/topbar";
|
import topbar from "../vendor/topbar";
|
||||||
import { ChessBoard } from "./hooks/chessBoard";
|
import { ChessBoard } from "./hooks/chessBoard";
|
||||||
import { CopyFen } from "./hooks/copyFen"
|
import { CopyFen } from "./hooks/copyFen";
|
||||||
|
|
||||||
let Hooks = {
|
let Hooks = {
|
||||||
...colocatedHooks,
|
...colocatedHooks,
|
||||||
ChessBoard,
|
ChessBoard,
|
||||||
CopyFen
|
CopyFen,
|
||||||
};
|
};
|
||||||
|
|
||||||
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
|
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// JavaScript for controller-rendered (non-LiveView) pages such as the landing
|
||||||
|
// page. Keep this small: no Phoenix Socket, LiveView, hooks, or topbar.
|
||||||
|
import "phoenix_html";
|
||||||
|
import "./nav";
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// Plain-DOM mobile navigation. It lives outside the LiveView hook system so it
|
||||||
|
// also runs on controller-rendered pages such as the landing page.
|
||||||
|
|
||||||
|
const WRAP = ".nav-wrap";
|
||||||
|
const TOGGLE = ".menu-button";
|
||||||
|
const LINKS = ".nav-links";
|
||||||
|
|
||||||
|
const setOpen = (open) => {
|
||||||
|
const wrap = document.querySelector(WRAP);
|
||||||
|
const links = wrap?.querySelector(LINKS);
|
||||||
|
const button = wrap?.querySelector(TOGGLE);
|
||||||
|
|
||||||
|
if (!links) return;
|
||||||
|
|
||||||
|
links.classList.toggle("open", open);
|
||||||
|
button?.setAttribute("aria-expanded", String(open));
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("click", (event) => {
|
||||||
|
const target = event.target instanceof Element ? event.target : null;
|
||||||
|
if (!target) return;
|
||||||
|
|
||||||
|
if (target.closest(TOGGLE)) {
|
||||||
|
const links = document.querySelector(LINKS);
|
||||||
|
setOpen(!links?.classList.contains("open"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.closest(`${LINKS} a`)) {
|
||||||
|
setOpen(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target.closest(WRAP)) {
|
||||||
|
setOpen(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
setOpen(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
Vendored
-1214
File diff suppressed because it is too large
Load Diff
Vendored
-9318
File diff suppressed because it is too large
Load Diff
+6
-1
@@ -36,6 +36,11 @@ config :chesstrainer, :ratings,
|
|||||||
window_days: 7,
|
window_days: 7,
|
||||||
rd_inflation_c: 10.0
|
rd_inflation_c: 10.0
|
||||||
|
|
||||||
|
# Public codes of the endgames pinned to the landing-page puzzle grid, in
|
||||||
|
# display order. When empty (or short) the grid is topped up with a date-seeded
|
||||||
|
# selection from the database, so it stays stable for a given day.
|
||||||
|
config :chesstrainer, :curated_endgame_codes, []
|
||||||
|
|
||||||
# Configure the endpoint
|
# Configure the endpoint
|
||||||
config :chesstrainer, ChesstrainerWeb.Endpoint,
|
config :chesstrainer, ChesstrainerWeb.Endpoint,
|
||||||
url: [host: "localhost"],
|
url: [host: "localhost"],
|
||||||
@@ -66,7 +71,7 @@ config :esbuild,
|
|||||||
version: "0.25.4",
|
version: "0.25.4",
|
||||||
chesstrainer: [
|
chesstrainer: [
|
||||||
args:
|
args:
|
||||||
~w(js/app.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.),
|
~w(js/app.js js/marketing.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.),
|
||||||
cd: Path.expand("../assets", __DIR__),
|
cd: Path.expand("../assets", __DIR__),
|
||||||
env: %{"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]}
|
env: %{"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]}
|
||||||
]
|
]
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ config :chesstrainer, Chesstrainer.Repo,
|
|||||||
config :chesstrainer, ChesstrainerWeb.Endpoint,
|
config :chesstrainer, ChesstrainerWeb.Endpoint,
|
||||||
# Binding to loopback ipv4 address prevents access from other machines.
|
# Binding to loopback ipv4 address prevents access from other machines.
|
||||||
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
||||||
http: [ip: {127, 0, 0, 1}],
|
http: [ip: {0, 0, 0, 0}],
|
||||||
check_origin: false,
|
check_origin: false,
|
||||||
code_reloader: true,
|
code_reloader: true,
|
||||||
debug_errors: true,
|
debug_errors: true,
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# The landing page is a server-rendered dead view
|
||||||
|
|
||||||
|
The marketing home page is a controller-rendered page (a "dead view") rather
|
||||||
|
than a LiveView. It shows a static board preview of the first curated endgame
|
||||||
|
and links to `/endgames/<public code>/play`; the puzzle is not playable on the
|
||||||
|
home page. Curated puzzle cards are ordinary links, and the puzzle count in the
|
||||||
|
learning strip is read from the database on each request.
|
||||||
|
|
||||||
|
LiveView renders its first response on the server too, so the SEO argument is
|
||||||
|
mostly about certainty: a dead view guarantees crawlers receive a complete
|
||||||
|
document without a websocket connecting. It also drops the LiveSocket round
|
||||||
|
trip and live-diff overhead from the page whose job is to be fast and
|
||||||
|
indexable. The cost is losing the interactive demo: visitors must follow a
|
||||||
|
link to try a puzzle, which is where attempts are recorded anyway.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- `HomeLive` and `HomeBoardComponent` are removed; all solving happens on
|
||||||
|
`/endgames/:public_code/play`.
|
||||||
|
- The board on the home page is `LandingComponents.board_preview/1` and is
|
||||||
|
deliberately inert.
|
||||||
|
- The "Try today's puzzle", "Begin with the basics", and each puzzle card link
|
||||||
|
straight to the first/selected endgame's player URL, using its public code.
|
||||||
|
- The puzzle count is request-time, not baked at build time, so it cannot go
|
||||||
|
stale between deploys.
|
||||||
|
- If the page feels slow in practice, the next step is a lighter
|
||||||
|
marketing-only JS bundle without the LiveSocket — deferred until measured.
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# Colour modes use a branded-inverse palette with role tokens
|
||||||
|
|
||||||
|
UI colour mode (`system`, `light`, `dark`) is a per-browser preference stored in
|
||||||
|
`localStorage["phx:theme"]`; `system` follows `prefers-color-scheme` and updates
|
||||||
|
live when the OS setting changes. The switch lives in the navbar
|
||||||
|
(`Layouts.colour_mode_toggle/1`) and the mode is applied before first paint by
|
||||||
|
the inline script in `root.html.heex`.
|
||||||
|
|
||||||
|
Dark mode is a branded inverse of the landing page's paper/ink/mint/coral
|
||||||
|
palette, not Phoenix's stock slate. The raw swatches are role-overloaded —
|
||||||
|
`--ink` is both body text and the fill behind white text; `--coral-dark` is both
|
||||||
|
small text on paper and the hover fill under white text — so `app.css` defines a
|
||||||
|
role layer (`--color-canvas`, `--color-body`, `--color-coral-control`, …) that
|
||||||
|
templates and stylesheets use. A colour mode overrides only the roles; light
|
||||||
|
mode reads them from the raw palette. The roles are exposed as `--color-*`, so
|
||||||
|
they also generate Tailwind utilities (`bg-canvas`, `text-muted`,
|
||||||
|
`border-hairline`) for templates that use utilities instead of named classes.
|
||||||
|
|
||||||
|
The chessboard is deliberately excluded. Chessground's brown board and cburnett
|
||||||
|
pieces stay identical in both modes, as does the landing-page preview board.
|
||||||
|
The board is content: recolouring it would make the same position look
|
||||||
|
different without helping the player, and the piece SVGs are tuned for the
|
||||||
|
brown board. Only the furniture around it — frame, time pill, promotion
|
||||||
|
picker — adapts.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- Adding or changing a colour mode means redefining role values, not hunting
|
||||||
|
selectors. Templates and `app.css` never reference the raw swatches.
|
||||||
|
- The Phoenix semantic tokens (`primary`, `base-*`, `accent`, …) are retuned to
|
||||||
|
the brand in both modes, so admin and auth screens do not turn blue in dark
|
||||||
|
mode. The missing `warning` and `error` dark values are now defined.
|
||||||
|
- Content colours (`--color-board-*`, `--color-piece-*`,
|
||||||
|
`--color-on-deep-*`) are intentionally identical across modes.
|
||||||
|
- The admin preview board (`assets/css/_board.css`) was left out of scope; it
|
||||||
|
remains light-only until revisited.
|
||||||
|
- Light-mode WCAG contrast failures are a knowing deferral, tracked in #61. The
|
||||||
|
role split means fixing them is a value change, not a refactor.
|
||||||
|
- The GDPR/ePrivacy position for the `localStorage` preference is tracked in
|
||||||
|
#60.
|
||||||
@@ -98,9 +98,6 @@ defmodule Chesstrainer.Accounts do
|
|||||||
def register_user(attrs) do
|
def register_user(attrs) do
|
||||||
%User{}
|
%User{}
|
||||||
|> User.registration_changeset(attrs)
|
|> User.registration_changeset(attrs)
|
||||||
# Accounts are usable straight away; email confirmation is intentionally off
|
|
||||||
# because no production mailer adapter is configured yet.
|
|
||||||
|> Ecto.Changeset.put_change(:confirmed_at, DateTime.utc_now(:second))
|
|
||||||
|> Repo.insert()
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -113,6 +110,48 @@ defmodule Chesstrainer.Accounts do
|
|||||||
User.registration_changeset(user, attrs, opts)
|
User.registration_changeset(user, attrs, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc ~S"""
|
||||||
|
Delivers the confirmation email instructions to the given user.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> deliver_user_confirmation_instructions(user, &url(~p"/users/confirm/#{&1}"))
|
||||||
|
{:ok, %{to: ..., body: ...}}
|
||||||
|
|
||||||
|
iex> deliver_user_confirmation_instructions(confirmed_user, &url(~p"/users/confirm/#{&1}"))
|
||||||
|
{:error, :already_confirmed}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def deliver_user_confirmation_instructions(%User{} = user, confirmation_url_fun)
|
||||||
|
when is_function(confirmation_url_fun, 1) do
|
||||||
|
if user.confirmed_at do
|
||||||
|
{:error, :already_confirmed}
|
||||||
|
else
|
||||||
|
{encoded_token, user_token} = UserToken.build_email_token(user, "confirm")
|
||||||
|
Repo.insert!(user_token)
|
||||||
|
UserNotifier.deliver_confirmation_instructions(user, confirmation_url_fun.(encoded_token))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Confirms a user by the given token.
|
||||||
|
|
||||||
|
If the token matches, the user account is marked as confirmed and the token is
|
||||||
|
deleted. The token is valid for one day.
|
||||||
|
"""
|
||||||
|
def confirm_user(token) do
|
||||||
|
with {:ok, query} <- UserToken.verify_confirmation_token_query(token),
|
||||||
|
%UserToken{sent_to: email} <- Repo.one(query),
|
||||||
|
%User{} = user <- Repo.get_by(User, email: email),
|
||||||
|
{:ok, user} <- Repo.update(User.confirm_changeset(user)),
|
||||||
|
{_count, _result} <-
|
||||||
|
Repo.delete_all(from(UserToken, where: [user_id: ^user.id, context: "confirm"])) do
|
||||||
|
{:ok, user}
|
||||||
|
else
|
||||||
|
_ -> :error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Updates a user's authority role.
|
Updates a user's authority role.
|
||||||
|
|
||||||
@@ -212,6 +251,48 @@ defmodule Chesstrainer.Accounts do
|
|||||||
|> update_user_and_delete_all_tokens()
|
|> update_user_and_delete_all_tokens()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc ~S"""
|
||||||
|
Delivers the reset password email instructions to the given user.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> deliver_user_reset_password_instructions(user, &url(~p"/users/reset-password/#{&1}"))
|
||||||
|
{:ok, %{to: ..., body: ...}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def deliver_user_reset_password_instructions(%User{} = user, reset_password_url_fun)
|
||||||
|
when is_function(reset_password_url_fun, 1) do
|
||||||
|
{encoded_token, user_token} = UserToken.build_email_token(user, "reset_password")
|
||||||
|
Repo.insert!(user_token)
|
||||||
|
UserNotifier.deliver_reset_password_instructions(user, reset_password_url_fun.(encoded_token))
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gets the user with the given reset password token.
|
||||||
|
|
||||||
|
Returns `nil` if the token is invalid or has expired.
|
||||||
|
"""
|
||||||
|
def get_user_by_reset_password_token(token) do
|
||||||
|
with {:ok, query} <- UserToken.verify_reset_password_token_query(token),
|
||||||
|
%UserToken{sent_to: email} <- Repo.one(query),
|
||||||
|
%User{} = user <- Repo.get_by(User, email: email) do
|
||||||
|
user
|
||||||
|
else
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Resets the user password.
|
||||||
|
|
||||||
|
Returns a tuple with the updated user, as well as a list of expired tokens.
|
||||||
|
"""
|
||||||
|
def reset_user_password(user, attrs) do
|
||||||
|
user
|
||||||
|
|> User.password_changeset(attrs)
|
||||||
|
|> update_user_and_delete_all_tokens()
|
||||||
|
end
|
||||||
|
|
||||||
## Deletion
|
## Deletion
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|||||||
@@ -17,6 +17,46 @@ defmodule Chesstrainer.Accounts.UserNotifier do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Deliver instructions to confirm account.
|
||||||
|
"""
|
||||||
|
def deliver_confirmation_instructions(user, url) do
|
||||||
|
deliver(user.email, "Confirmation instructions", """
|
||||||
|
|
||||||
|
==============================
|
||||||
|
|
||||||
|
Hi #{user.email},
|
||||||
|
|
||||||
|
You can confirm your account by visiting the URL below:
|
||||||
|
|
||||||
|
#{url}
|
||||||
|
|
||||||
|
If you didn't create an account with us, please ignore this.
|
||||||
|
|
||||||
|
==============================
|
||||||
|
""")
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Deliver instructions to reset a user password.
|
||||||
|
"""
|
||||||
|
def deliver_reset_password_instructions(user, url) do
|
||||||
|
deliver(user.email, "Reset password instructions", """
|
||||||
|
|
||||||
|
==============================
|
||||||
|
|
||||||
|
Hi #{user.email},
|
||||||
|
|
||||||
|
You can reset your password by visiting the URL below:
|
||||||
|
|
||||||
|
#{url}
|
||||||
|
|
||||||
|
If you didn't request this change, please ignore this.
|
||||||
|
|
||||||
|
==============================
|
||||||
|
""")
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Deliver instructions to update a user email.
|
Deliver instructions to update a user email.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ defmodule Chesstrainer.Accounts.UserToken do
|
|||||||
@rand_size 32
|
@rand_size 32
|
||||||
|
|
||||||
@change_email_validity_in_days 7
|
@change_email_validity_in_days 7
|
||||||
|
@confirm_validity_in_days 1
|
||||||
|
@reset_password_validity_in_days 1
|
||||||
@session_validity_in_days 14
|
@session_validity_in_days 14
|
||||||
|
|
||||||
@primary_key {:id, :binary_id, autogenerate: true}
|
@primary_key {:id, :binary_id, autogenerate: true}
|
||||||
@@ -121,6 +123,56 @@ defmodule Chesstrainer.Accounts.UserToken do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Checks if the token is valid and returns its underlying lookup query.
|
||||||
|
|
||||||
|
The query returns the user_token found by the token, if any.
|
||||||
|
|
||||||
|
This is used to validate requests to confirm the user account.
|
||||||
|
The given token is valid if it matches its hashed counterpart in the
|
||||||
|
database and if it has not expired (after @confirm_validity_in_days).
|
||||||
|
"""
|
||||||
|
def verify_confirmation_token_query(token) do
|
||||||
|
case Base.url_decode64(token, padding: false) do
|
||||||
|
{:ok, decoded_token} ->
|
||||||
|
hashed_token = :crypto.hash(@hash_algorithm, decoded_token)
|
||||||
|
|
||||||
|
query =
|
||||||
|
from token in by_token_and_context_query(hashed_token, "confirm"),
|
||||||
|
where: token.inserted_at > ago(@confirm_validity_in_days, "day")
|
||||||
|
|
||||||
|
{:ok, query}
|
||||||
|
|
||||||
|
:error ->
|
||||||
|
:error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Checks if the token is valid and returns its underlying lookup query.
|
||||||
|
|
||||||
|
The query returns the user_token found by the token, if any.
|
||||||
|
|
||||||
|
This is used to validate requests to reset the user password.
|
||||||
|
The given token is valid if it matches its hashed counterpart in the
|
||||||
|
database and if it has not expired (after @reset_password_validity_in_days).
|
||||||
|
"""
|
||||||
|
def verify_reset_password_token_query(token) do
|
||||||
|
case Base.url_decode64(token, padding: false) do
|
||||||
|
{:ok, decoded_token} ->
|
||||||
|
hashed_token = :crypto.hash(@hash_algorithm, decoded_token)
|
||||||
|
|
||||||
|
query =
|
||||||
|
from token in by_token_and_context_query(hashed_token, "reset_password"),
|
||||||
|
where: token.inserted_at > ago(@reset_password_validity_in_days, "day")
|
||||||
|
|
||||||
|
{:ok, query}
|
||||||
|
|
||||||
|
:error ->
|
||||||
|
:error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp by_token_and_context_query(token, context) do
|
defp by_token_and_context_query(token, context) do
|
||||||
from UserToken, where: [token: ^token, context: ^context]
|
from UserToken, where: [token: ^token, context: ^context]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
defmodule Chesstrainer.DailyPuzzles do
|
||||||
|
@moduledoc """
|
||||||
|
Assigns a single endgame to each UTC day.
|
||||||
|
|
||||||
|
The assignment is persisted so every request and every user sees the same
|
||||||
|
featured puzzle for the day. Assignment is race-safe: concurrent first
|
||||||
|
requests rely on the unique date constraint and read back the winning row.
|
||||||
|
|
||||||
|
Selection prefers endgames not used in the last 30 days and falls back to
|
||||||
|
any endgame when that pool is exhausted.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Ecto.Query, warn: false
|
||||||
|
|
||||||
|
alias Chesstrainer.DailyPuzzles.DailyPuzzle
|
||||||
|
alias Chesstrainer.Endgames.Endgame
|
||||||
|
alias Chesstrainer.Repo
|
||||||
|
|
||||||
|
@recent_days 30
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns today's endgame (UTC), assigning one if needed.
|
||||||
|
|
||||||
|
Returns `nil` when no endgames exist.
|
||||||
|
"""
|
||||||
|
def today, do: for_date(Date.utc_today())
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the endgame assigned to `date`, assigning one if needed.
|
||||||
|
|
||||||
|
Returns `nil` when no endgames exist.
|
||||||
|
"""
|
||||||
|
def for_date(%Date{} = date) do
|
||||||
|
case get_for_date(date) do
|
||||||
|
nil -> assign_for_date(date)
|
||||||
|
endgame -> endgame
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_for_date(date) do
|
||||||
|
case Repo.get_by(DailyPuzzle, date: date) do
|
||||||
|
nil -> nil
|
||||||
|
daily_puzzle -> Repo.preload(daily_puzzle, endgame: :themes).endgame
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp assign_for_date(date) do
|
||||||
|
case pick_endgame_id(date) do
|
||||||
|
nil ->
|
||||||
|
nil
|
||||||
|
|
||||||
|
endgame_id ->
|
||||||
|
%DailyPuzzle{}
|
||||||
|
|> DailyPuzzle.changeset(%{date: date, endgame_id: endgame_id})
|
||||||
|
|> Repo.insert(on_conflict: :nothing, conflict_target: :date)
|
||||||
|
|
||||||
|
get_for_date(date)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp pick_endgame_id(date) do
|
||||||
|
cutoff = Date.add(date, -@recent_days)
|
||||||
|
|
||||||
|
recent_ids =
|
||||||
|
Repo.all(
|
||||||
|
from daily_puzzle in DailyPuzzle,
|
||||||
|
where: daily_puzzle.date >= ^cutoff,
|
||||||
|
select: daily_puzzle.endgame_id
|
||||||
|
)
|
||||||
|
|
||||||
|
eligible_ids =
|
||||||
|
Repo.all(
|
||||||
|
from endgame in Endgame,
|
||||||
|
where: endgame.id not in ^recent_ids,
|
||||||
|
select: endgame.id
|
||||||
|
)
|
||||||
|
|
||||||
|
ids =
|
||||||
|
case eligible_ids do
|
||||||
|
[] -> Repo.all(from endgame in Endgame, select: endgame.id)
|
||||||
|
ids -> ids
|
||||||
|
end
|
||||||
|
|
||||||
|
case ids do
|
||||||
|
[] -> nil
|
||||||
|
ids -> Enum.random(ids)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
defmodule Chesstrainer.DailyPuzzles.DailyPuzzle do
|
||||||
|
@moduledoc """
|
||||||
|
A persisted endgame assignment for one UTC day.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
alias Chesstrainer.Endgames.Endgame
|
||||||
|
|
||||||
|
@foreign_key_type :binary_id
|
||||||
|
|
||||||
|
schema "daily_puzzles" do
|
||||||
|
field :date, :date
|
||||||
|
|
||||||
|
belongs_to :endgame, Endgame
|
||||||
|
|
||||||
|
timestamps(type: :utc_datetime)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def changeset(daily_puzzle, attrs) do
|
||||||
|
daily_puzzle
|
||||||
|
|> cast(attrs, [:date, :endgame_id])
|
||||||
|
|> validate_required([:date, :endgame_id])
|
||||||
|
|> unique_constraint(:date)
|
||||||
|
|> foreign_key_constraint(:endgame_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -21,6 +21,74 @@ defmodule Chesstrainer.Endgames do
|
|||||||
Repo.all(Endgame)
|
Repo.all(Endgame)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns a random endgame, or `nil` when none exist.
|
||||||
|
"""
|
||||||
|
def random_endgame do
|
||||||
|
Repo.one(from e in Endgame, order_by: fragment("RANDOM()"), limit: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the number of stored endgames, each of which is played as a puzzle.
|
||||||
|
"""
|
||||||
|
def count_endgames do
|
||||||
|
Repo.aggregate(Endgame, :count)
|
||||||
|
end
|
||||||
|
|
||||||
|
@curated_count 3
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns curated endgames for the landing page, with themes preloaded.
|
||||||
|
|
||||||
|
Curation is the configured list of `:curated_endgame_codes`; codes that do not
|
||||||
|
resolve are skipped. The list is topped up with a date-seeded selection from
|
||||||
|
the database so it is stable for a given day, and is empty when no endgames
|
||||||
|
exist.
|
||||||
|
"""
|
||||||
|
def curated_endgames(count \\ @curated_count) do
|
||||||
|
codes = Application.get_env(:chesstrainer, :curated_endgame_codes, [])
|
||||||
|
|
||||||
|
curated =
|
||||||
|
codes
|
||||||
|
|> Enum.flat_map(&endgame_for_code/1)
|
||||||
|
|> Enum.uniq_by(& &1.id)
|
||||||
|
|
||||||
|
fill_curated(curated, count)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp endgame_for_code(code) do
|
||||||
|
case Repo.get_by(Endgame, public_code: code) do
|
||||||
|
nil -> []
|
||||||
|
endgame -> [Repo.preload(endgame, :themes)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp fill_curated(endgames, count) when length(endgames) >= count,
|
||||||
|
do: Enum.take(endgames, count)
|
||||||
|
|
||||||
|
defp fill_curated(endgames, count) do
|
||||||
|
exclude_ids = Enum.map(endgames, & &1.id)
|
||||||
|
endgames ++ date_seeded_endgames(exclude_ids, count - length(endgames))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp date_seeded_endgames([], limit), do: date_seeded_endgames_query(Endgame, limit)
|
||||||
|
|
||||||
|
defp date_seeded_endgames(exclude_ids, limit) do
|
||||||
|
Endgame
|
||||||
|
|> where([e], e.id not in ^exclude_ids)
|
||||||
|
|> date_seeded_endgames_query(limit)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp date_seeded_endgames_query(query, limit) do
|
||||||
|
today = Date.utc_today()
|
||||||
|
|
||||||
|
query
|
||||||
|
|> preload(:themes)
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.sort_by(fn endgame -> :erlang.phash2({today, endgame.id}) end)
|
||||||
|
|> Enum.take(limit)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns the distinct Keys across all endgames, sorted.
|
Returns the distinct Keys across all endgames, sorted.
|
||||||
"""
|
"""
|
||||||
@@ -99,6 +167,15 @@ defmodule Chesstrainer.Endgames do
|
|||||||
Repo.get_by!(Endgame, public_code: public_code)
|
Repo.get_by!(Endgame, public_code: public_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gets a single endgame by its public code with its themes preloaded.
|
||||||
|
"""
|
||||||
|
def get_endgame_by_public_code_with_themes!(public_code) do
|
||||||
|
Endgame
|
||||||
|
|> Repo.get_by!(public_code: public_code)
|
||||||
|
|> Repo.preload(:themes)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Finds endgames by database id, public code, or FEN.
|
Finds endgames by database id, public code, or FEN.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
defmodule Chesstrainer.FEN do
|
defmodule Chesstrainer.FEN do
|
||||||
|
@board_pieces ~w(p n b r q k P N B R Q K)
|
||||||
|
|
||||||
@spec color_from_fen(String.t()) :: :white | :black | nil
|
@spec color_from_fen(String.t()) :: :white | :black | nil
|
||||||
def color_from_fen(fen) do
|
def color_from_fen(fen) do
|
||||||
fen
|
fen
|
||||||
@@ -92,6 +94,56 @@ defmodule Chesstrainer.FEN do
|
|||||||
|
|
||||||
def piece_count(_fen), do: nil
|
def piece_count(_fen), do: nil
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the board field of a FEN as eight ranks, each a list of eight squares,
|
||||||
|
where each square is a piece letter or `nil`.
|
||||||
|
|
||||||
|
Returns `nil` when the board field is not a well-formed FEN board. Only the
|
||||||
|
board field is read; the active colour and clocks are ignored.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> Chesstrainer.FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") |> Enum.at(2)
|
||||||
|
[nil, nil, nil, "k", nil, nil, nil, nil]
|
||||||
|
|
||||||
|
iex> Chesstrainer.FEN.board("not a fen")
|
||||||
|
nil
|
||||||
|
"""
|
||||||
|
@spec board(String.t() | nil) :: [[String.t() | nil]] | nil
|
||||||
|
def board(fen) when is_binary(fen) do
|
||||||
|
case String.split(fen, " ") do
|
||||||
|
[board | _] -> parse_board(board)
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def board(_fen), do: nil
|
||||||
|
|
||||||
|
defp parse_board(board) do
|
||||||
|
case String.split(board, "/") do
|
||||||
|
ranks when length(ranks) == 8 ->
|
||||||
|
squares = Enum.map(ranks, &parse_rank/1)
|
||||||
|
if Enum.all?(squares, &is_list/1), do: squares, else: nil
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_rank(rank) do
|
||||||
|
rank
|
||||||
|
|> String.graphemes()
|
||||||
|
|> Enum.reduce_while([], fn
|
||||||
|
<<c>>, acc when c in ?1..?8 -> {:cont, List.duplicate(nil, c - ?0) ++ acc}
|
||||||
|
piece, acc when piece in @board_pieces -> {:cont, [piece | acc]}
|
||||||
|
_other, _acc -> {:halt, nil}
|
||||||
|
end)
|
||||||
|
|> case do
|
||||||
|
squares when is_list(squares) and length(squares) == 8 -> Enum.reverse(squares)
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp board_piece_count(board) do
|
defp board_piece_count(board) do
|
||||||
board
|
board
|
||||||
|> String.graphemes()
|
|> String.graphemes()
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ defmodule ChesstrainerWeb do
|
|||||||
import Phoenix.HTML
|
import Phoenix.HTML
|
||||||
# Core UI components
|
# Core UI components
|
||||||
import ChesstrainerWeb.CoreComponents
|
import ChesstrainerWeb.CoreComponents
|
||||||
|
# Landing-page primitives (pill buttons, marketing icons)
|
||||||
|
import ChesstrainerWeb.LandingComponents
|
||||||
|
|
||||||
# Common modules used in templates
|
# Common modules used in templates
|
||||||
alias Phoenix.LiveView.JS
|
alias Phoenix.LiveView.JS
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
with doc strings and declarative assigns. You may customize and style
|
with doc strings and declarative assigns. You may customize and style
|
||||||
them in any way you want, based on your application growth and needs.
|
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,
|
The foundation for styling is Tailwind CSS, a utility-first CSS framework.
|
||||||
augmented with daisyUI, a Tailwind CSS plugin that provides UI components
|
Semantic colors such as `base-100`, `base-content` and `primary` are defined
|
||||||
and themes. Here are useful references:
|
in `assets/css/app.css` and switch with the `data-theme` attribute. Here are
|
||||||
|
useful references:
|
||||||
* [daisyUI](https://daisyui.com/docs/intro/) - a good place to get
|
|
||||||
started and see the available components.
|
|
||||||
|
|
||||||
* [Tailwind CSS](https://tailwindcss.com) - the foundational framework
|
* [Tailwind CSS](https://tailwindcss.com) - the foundational framework
|
||||||
we build on. You will use it for layout, sizing, flexbox, grid, and
|
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
|
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 """
|
@doc """
|
||||||
Renders flash notices.
|
Renders flash notices.
|
||||||
|
|
||||||
@@ -63,13 +79,13 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
id={@id}
|
id={@id}
|
||||||
phx-click={JS.push("lv:clear-flash", value: %{key: @kind}) |> hide("##{@id}")}
|
phx-click={JS.push("lv:clear-flash", value: %{key: @kind}) |> hide("##{@id}")}
|
||||||
role="alert"
|
role="alert"
|
||||||
class="toast toast-top toast-end z-50"
|
class="fixed right-4 top-4 z-50 flex flex-col gap-2"
|
||||||
{@rest}
|
{@rest}
|
||||||
>
|
>
|
||||||
<div class={[
|
<div class={[
|
||||||
"alert w-80 sm:w-96 max-w-80 sm:max-w-96 text-wrap",
|
"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 && "alert-info",
|
@kind == :info && "border-info bg-info text-info-content",
|
||||||
@kind == :error && "alert-error"
|
@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 == :info} name="hero-information-circle" class="size-5 shrink-0" />
|
||||||
<.icon :if={@kind == :error} name="hero-exclamation-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 :rest, :global, include: ~w(href navigate patch method download name value disabled)
|
||||||
attr :class, :any
|
attr :class, :any
|
||||||
attr :variant, :string, values: ~w(primary)
|
attr :variant, :string, values: ~w(primary secondary ghost danger)
|
||||||
slot :inner_block, required: true
|
slot :inner_block, required: true
|
||||||
|
|
||||||
def button(%{rest: rest} = assigns) do
|
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 =
|
assigns =
|
||||||
assign_new(assigns, :class, fn ->
|
assign(assigns, :class, [
|
||||||
["btn", Map.fetch!(variants, assigns[:variant])]
|
"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",
|
||||||
end)
|
Map.fetch!(variants, assigns[:variant]),
|
||||||
|
assigns[:class]
|
||||||
|
])
|
||||||
|
|
||||||
if rest[:href] || rest[:navigate] || rest[:patch] do
|
if rest[:href] || rest[:navigate] || rest[:patch] do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -181,8 +205,11 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
|
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 :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 :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 :class, :any, default: nil, doc: "extra classes merged with the default input classes"
|
||||||
attr :error_class, :any, default: nil, doc: "the input error class to use over defaults"
|
|
||||||
|
attr :error_class, :any,
|
||||||
|
default: nil,
|
||||||
|
doc: "extra classes merged with the default error classes"
|
||||||
|
|
||||||
attr :rest, :global,
|
attr :rest, :global,
|
||||||
include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength
|
include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength
|
||||||
@@ -212,8 +239,8 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class="fieldset mb-2">
|
<div class="mb-3">
|
||||||
<label for={@id}>
|
<label for={@id} class="flex items-center gap-2">
|
||||||
<input
|
<input
|
||||||
type="hidden"
|
type="hidden"
|
||||||
name={@name}
|
name={@name}
|
||||||
@@ -221,17 +248,16 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
disabled={@rest[:disabled]}
|
disabled={@rest[:disabled]}
|
||||||
form={@rest[:form]}
|
form={@rest[:form]}
|
||||||
/>
|
/>
|
||||||
<span class="label">
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id={@id}
|
id={@id}
|
||||||
name={@name}
|
name={@name}
|
||||||
value="true"
|
value="true"
|
||||||
checked={@checked}
|
checked={@checked}
|
||||||
class={@class || "checkbox checkbox-sm"}
|
class={[checkbox_class(), @class]}
|
||||||
{@rest}
|
{@rest}
|
||||||
/>{@label}
|
/>
|
||||||
</span>
|
<span class="text-sm text-base-content">{@label}</span>
|
||||||
</label>
|
</label>
|
||||||
<.error :for={msg <- @errors}>{msg}</.error>
|
<.error :for={msg <- @errors}>{msg}</.error>
|
||||||
</div>
|
</div>
|
||||||
@@ -240,13 +266,17 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
|
|
||||||
def input(%{type: "select"} = assigns) do
|
def input(%{type: "select"} = assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="fieldset mb-2">
|
<div class="mb-3">
|
||||||
<label for={@id}>
|
<label for={@id}>
|
||||||
<span :if={@label} class="label mb-1">{@label}</span>
|
<span :if={@label} class={label_class()}>{@label}</span>
|
||||||
<select
|
<select
|
||||||
id={@id}
|
id={@id}
|
||||||
name={@name}
|
name={@name}
|
||||||
class={[@class || "w-full select", @errors != [] && (@error_class || "select-error")]}
|
class={[
|
||||||
|
input_class(),
|
||||||
|
@errors != [] && (@error_class || input_error_class()),
|
||||||
|
@class
|
||||||
|
]}
|
||||||
multiple={@multiple}
|
multiple={@multiple}
|
||||||
{@rest}
|
{@rest}
|
||||||
>
|
>
|
||||||
@@ -261,15 +291,16 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
|
|
||||||
def input(%{type: "textarea"} = assigns) do
|
def input(%{type: "textarea"} = assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="fieldset mb-2">
|
<div class="mb-3">
|
||||||
<label for={@id}>
|
<label for={@id}>
|
||||||
<span :if={@label} class="label mb-1">{@label}</span>
|
<span :if={@label} class={label_class()}>{@label}</span>
|
||||||
<textarea
|
<textarea
|
||||||
id={@id}
|
id={@id}
|
||||||
name={@name}
|
name={@name}
|
||||||
class={[
|
class={[
|
||||||
@class || "w-full textarea",
|
input_class(),
|
||||||
@errors != [] && (@error_class || "textarea-error")
|
@errors != [] && (@error_class || input_error_class()),
|
||||||
|
@class
|
||||||
]}
|
]}
|
||||||
{@rest}
|
{@rest}
|
||||||
>{Phoenix.HTML.Form.normalize_value("textarea", @value)}</textarea>
|
>{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...
|
# All other inputs text, datetime-local, url, password, etc. are handled here...
|
||||||
def input(assigns) do
|
def input(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="fieldset mb-2">
|
<div class="mb-3">
|
||||||
<label for={@id}>
|
<label for={@id}>
|
||||||
<span :if={@label} class="label mb-1">{@label}</span>
|
<span :if={@label} class={label_class()}>{@label}</span>
|
||||||
<input
|
<input
|
||||||
type={@type}
|
type={@type}
|
||||||
name={@name}
|
name={@name}
|
||||||
id={@id}
|
id={@id}
|
||||||
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
|
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
|
||||||
class={[
|
class={[
|
||||||
@class || "w-full input",
|
input_class(),
|
||||||
@errors != [] && (@error_class || "input-error")
|
@errors != [] && (@error_class || input_error_class()),
|
||||||
|
@class
|
||||||
]}
|
]}
|
||||||
{@rest}
|
{@rest}
|
||||||
/>
|
/>
|
||||||
@@ -326,7 +358,7 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
<h1 class="text-lg font-semibold leading-8">
|
<h1 class="text-lg font-semibold leading-8">
|
||||||
{render_slot(@inner_block)}
|
{render_slot(@inner_block)}
|
||||||
</h1>
|
</h1>
|
||||||
<p :if={@subtitle != []} class="text-sm text-base-content/70">
|
<p :if={@subtitle != []} class="text-sm text-base-content/70 mt-4">
|
||||||
{render_slot(@subtitle)}
|
{render_slot(@subtitle)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -367,7 +399,7 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
end
|
end
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<table class="table table-zebra">
|
<table class={table_class()}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th :for={col <- @col}>{col[:label]}</th>
|
<th :for={col <- @col}>{col[:label]}</th>
|
||||||
@@ -414,17 +446,49 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
|
|
||||||
def list(assigns) do
|
def list(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<ul class="list">
|
<ul class="divide-y divide-base-200">
|
||||||
<li :for={item <- @item} class="list-row">
|
<li :for={item <- @item} class="flex gap-3 py-3">
|
||||||
<div class="list-col-grow">
|
<div class="flex-1 space-y-1">
|
||||||
<div class="font-bold">{item.title}</div>
|
<div class="font-semibold">{item.title}</div>
|
||||||
<div>{render_slot(item)}</div>
|
<div class="text-sm text-base-content/70">{render_slot(item)}</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
"""
|
"""
|
||||||
end
|
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 """
|
@doc """
|
||||||
Renders a [Heroicon](https://heroicons.com).
|
Renders a [Heroicon](https://heroicons.com).
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ defmodule ChesstrainerWeb.EndgameList do
|
|||||||
~H"""
|
~H"""
|
||||||
<div class="mb-6 space-y-3">
|
<div class="mb-6 space-y-3">
|
||||||
<div :if={@selected_themes != []} class="flex flex-wrap gap-2">
|
<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}
|
{theme.name}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -139,24 +139,30 @@ defmodule ChesstrainerWeb.EndgameList do
|
|||||||
>
|
>
|
||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</.badge>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-3 sm:flex-row">
|
<div class="flex flex-col gap-3 sm:flex-row">
|
||||||
<form id="theme-filter-form" phx-change="search_themes" class="flex-1">
|
<form id="theme-filter-form" phx-change="search_themes" class="flex-1">
|
||||||
<input
|
<.input
|
||||||
type="text"
|
|
||||||
name="theme_search"
|
name="theme_search"
|
||||||
value={@theme_query}
|
value={@theme_query}
|
||||||
phx-debounce="200"
|
phx-debounce="200"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder="Filter by theme…"
|
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}>
|
<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}
|
{theme.name}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
@@ -164,12 +170,13 @@ defmodule ChesstrainerWeb.EndgameList do
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form id="key-filter-form" phx-change="filter_key" class="flex-1">
|
<form id="key-filter-form" phx-change="filter_key" class="flex-1">
|
||||||
<select name="key" class="select w-full">
|
<.input
|
||||||
<option value="" selected={is_nil(@selected_key)}>All keys</option>
|
type="select"
|
||||||
<option :for={key <- @keys} value={key} selected={key == @selected_key}>
|
name="key"
|
||||||
{key}
|
prompt="All keys"
|
||||||
</option>
|
options={@keys}
|
||||||
</select>
|
value={@selected_key}
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -202,7 +209,9 @@ defmodule ChesstrainerWeb.EndgameList do
|
|||||||
>
|
>
|
||||||
<span class="font-semibold">{group.key}</span>
|
<span class="font-semibold">{group.key}</span>
|
||||||
<span class="flex items-center gap-2 text-sm">
|
<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
|
<.icon
|
||||||
name={if group.expanded, do: "hero-chevron-down", else: "hero-chevron-right"}
|
name={if group.expanded, do: "hero-chevron-down", else: "hero-chevron-right"}
|
||||||
class="size-4"
|
class="size-4"
|
||||||
@@ -210,7 +219,7 @@ defmodule ChesstrainerWeb.EndgameList do
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<table :if={group.expanded} class="table table-zebra">
|
<table :if={group.expanded} class={table_class()}>
|
||||||
<thead>
|
<thead>
|
||||||
{render_slot(@header)}
|
{render_slot(@header)}
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -0,0 +1,322 @@
|
|||||||
|
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 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
|
||||||
@@ -52,57 +52,125 @@ defmodule ChesstrainerWeb.Layouts do
|
|||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Renders the application navbar.
|
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,
|
attr :current_scope, :map,
|
||||||
default: nil,
|
default: nil,
|
||||||
doc: "the current [scope](https://phoenix.hexdocs.pm/scopes.html)"
|
doc: "the current [scope](https://phoenix.hexdocs.pm/scopes.html)"
|
||||||
|
|
||||||
def navbar(assigns) do
|
def navbar(assigns) do
|
||||||
|
assigns = assign(assigns, :nav_links, nav_links(assigns.current_scope))
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<header class="navbar px-4 sm:px-6 lg:px-8">
|
<header>
|
||||||
<div class="flex-1">
|
<nav class="nav-wrap" aria-label="Main navigation">
|
||||||
<a href="/" class="flex-1 flex w-fit items-center gap-2">
|
<a class="brand" href="/" aria-label="Lucid Chess home">
|
||||||
<img src={~p"/images/logo.svg"} width="36" />
|
<span class="brand-mark">♞</span>
|
||||||
<span class="text-sm font-semibold">v{Application.spec(:phoenix, :vsn)}</span>
|
<span>LUCID</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
|
||||||
<div class="flex-none">
|
<div class="nav-right">
|
||||||
<ul class="flex flex-column px-1 space-x-4 items-center">
|
<.colour_mode_toggle />
|
||||||
<li>
|
|
||||||
<a href="/endgames" class="btn btn-ghost">Endgames</a>
|
<button
|
||||||
</li>
|
class="menu-button"
|
||||||
<li :if={@current_scope && Role.admin?(@current_scope.user.role)}>
|
type="button"
|
||||||
<a href="/admin/endgames" class="btn btn-ghost">Admin</a>
|
aria-expanded="false"
|
||||||
</li>
|
aria-controls="nav-links"
|
||||||
<li>
|
aria-label="Toggle menu"
|
||||||
<.theme_toggle />
|
>
|
||||||
</li>
|
<span></span>
|
||||||
<%= if @current_scope do %>
|
<span></span>
|
||||||
<li>
|
</button>
|
||||||
<span class="text-sm">{@current_scope.user.username}</span>
|
|
||||||
</li>
|
<div class="nav-links" id="nav-links">
|
||||||
<li>
|
<%= for link <- @nav_links do %>
|
||||||
<.link navigate={~p"/users/settings"} class="btn btn-ghost">Settings</.link>
|
<%= if link[:kind] == :text do %>
|
||||||
</li>
|
<span class="nav-user">{link.label}</span>
|
||||||
<li>
|
|
||||||
<.link href={~p"/users/log-out"} method="delete" class="btn btn-ghost">
|
|
||||||
Log out
|
|
||||||
</.link>
|
|
||||||
</li>
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<li>
|
<.link href={link.href} method={link[:method]}>{link.label}</.link>
|
||||||
<.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 %>
|
<% end %>
|
||||||
</ul>
|
<% end %>
|
||||||
|
|
||||||
|
<.pill_button variant={:nav} href="/endgames">
|
||||||
|
Start training <.icon_arrow />
|
||||||
|
</.pill_button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
"""
|
"""
|
||||||
end
|
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 """
|
@doc """
|
||||||
Shows the flash group with standard titles and content.
|
Shows the flash group with standard titles and content.
|
||||||
|
|
||||||
@@ -153,35 +221,54 @@ defmodule ChesstrainerWeb.Layouts do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@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"""
|
~H"""
|
||||||
<div class="card relative flex flex-row items-center border-2 border-base-300 bg-base-300 rounded-full">
|
<div
|
||||||
<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]" />
|
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
|
<button
|
||||||
class="flex p-2 cursor-pointer w-1/3"
|
type="button"
|
||||||
phx-click={JS.dispatch("phx:set-theme")}
|
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"
|
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" />
|
<.icon name="hero-computer-desktop-micro" class="size-4 opacity-75 hover:opacity-100" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="flex p-2 cursor-pointer w-1/3"
|
type="button"
|
||||||
phx-click={JS.dispatch("phx:set-theme")}
|
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"
|
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" />
|
<.icon name="hero-sun-micro" class="size-4 opacity-75 hover:opacity-100" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="flex p-2 cursor-pointer w-1/3"
|
type="button"
|
||||||
phx-click={JS.dispatch("phx:set-theme")}
|
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"
|
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" />
|
<.icon name="hero-moon-micro" class="size-4 opacity-75 hover:opacity-100" />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -3,37 +3,135 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<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>
|
||||||
<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) => {
|
const storedMode = () => {
|
||||||
if (theme === "system") {
|
try { return localStorage.getItem("phx:theme"); } catch (_) { return null; }
|
||||||
localStorage.removeItem("phx:theme");
|
};
|
||||||
document.documentElement.setAttribute("data-theme", systemTheme());
|
|
||||||
document.documentElement.setAttribute("data-theme-source", "system");
|
const persistMode = (mode) => {
|
||||||
} else {
|
try {
|
||||||
localStorage.setItem("phx:theme", theme);
|
if (mode === "system") localStorage.removeItem("phx:theme");
|
||||||
document.documentElement.setAttribute("data-theme", theme);
|
else localStorage.setItem("phx:theme", mode);
|
||||||
document.documentElement.setAttribute("data-theme-source", "user");
|
} 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");
|
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");
|
||||||
}
|
}
|
||||||
window.addEventListener("storage", (e) => e.key === "phx:theme" && setTheme(e.newValue || "system"));
|
|
||||||
|
|
||||||
window.addEventListener("phx:set-theme", (e) => setTheme(e.target.dataset.phxTheme));
|
syncChecked();
|
||||||
|
};
|
||||||
|
|
||||||
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
|
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") {
|
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>
|
<body>
|
||||||
<Layouts.navbar current_scope={@current_scope} />
|
<Layouts.navbar current_scope={@current_scope} />
|
||||||
{@inner_content}
|
{@inner_content}
|
||||||
|
<Layouts.footer />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
defmodule ChesstrainerWeb.PageController do
|
defmodule ChesstrainerWeb.PageController do
|
||||||
use ChesstrainerWeb, :controller
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,4 +7,7 @@ defmodule ChesstrainerWeb.PageHTML do
|
|||||||
use ChesstrainerWeb, :html
|
use ChesstrainerWeb, :html
|
||||||
|
|
||||||
embed_templates "page_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
|
end
|
||||||
|
|||||||
@@ -1,160 +1,89 @@
|
|||||||
<Layouts.flash_group flash={@flash} />
|
<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">
|
<main>
|
||||||
<div class="mx-auto max-w-xl lg:mx-0">
|
<section class="hero">
|
||||||
<svg viewBox="0 0 71 48" class="h-12" aria-hidden="true">
|
<div class="hero-copy">
|
||||||
<path
|
<div class="eyebrow">
|
||||||
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"
|
<.icon_spark /> Endgames, made clear
|
||||||
fill="#FD4F00"
|
</div>
|
||||||
/>
|
<h1>
|
||||||
</svg>
|
Learn to see the <em>winning move.</em>
|
||||||
<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>
|
|
||||||
</h1>
|
</h1>
|
||||||
<Layouts.theme_toggle />
|
<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 class="board-stage" id="trainer">
|
||||||
|
<div class="coral-orbit" />
|
||||||
|
<div class="mint-orbit" />
|
||||||
|
<.board_preview endgame={@active_endgame} />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-balance">
|
<section class="learning-strip" id="method">
|
||||||
Peace of mind from prototype to production.
|
<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>
|
</p>
|
||||||
<p class="mt-4 leading-7 text-base-content/70">
|
</div>
|
||||||
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.
|
<div class="puzzle-grid">
|
||||||
</p>
|
<%= for {endgame, index} <- Enum.with_index(@endgames) do %>
|
||||||
<div class="flex">
|
<.puzzle_card
|
||||||
<div class="w-full sm:w-auto">
|
endgame={endgame}
|
||||||
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-3">
|
index={index}
|
||||||
<a
|
active={@active_endgame && endgame.id == @active_endgame.id}
|
||||||
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>
|
<% end %>
|
||||||
Guides & 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>
|
||||||
<div class="mt-10 grid grid-cols-1 gap-y-4 text-sm leading-6 text-base-content/80 sm:grid-cols-2">
|
</section>
|
||||||
|
|
||||||
|
<section class="progress-banner" id="progress">
|
||||||
<div>
|
<div>
|
||||||
<a
|
<span class="section-kicker">A calmer way to improve</span>
|
||||||
href="https://elixirforum.com"
|
<h2>
|
||||||
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"
|
Make the endgame <br /> your strongest phase.
|
||||||
>
|
</h2>
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<.pill_button variant={:light} navigate={play_path(@active_endgame)}>
|
||||||
|
Begin with the basics <.icon_arrow />
|
||||||
|
</.pill_button>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
defmodule ChesstrainerWeb.UserConfirmationController do
|
||||||
|
use ChesstrainerWeb, :controller
|
||||||
|
|
||||||
|
alias Chesstrainer.Accounts
|
||||||
|
|
||||||
|
def edit(conn, %{"token" => token}) do
|
||||||
|
case Accounts.confirm_user(token) do
|
||||||
|
{:ok, _user} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "User confirmed successfully.")
|
||||||
|
|> redirect(to: ~p"/users/log-in")
|
||||||
|
|
||||||
|
:error ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "User not found or token is invalid.")
|
||||||
|
|> redirect(to: ~p"/users/register")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -17,9 +17,24 @@ defmodule ChesstrainerWeb.UserSessionController do
|
|||||||
|> redirect(to: ~p"/users/log-in")
|
|> redirect(to: ~p"/users/log-in")
|
||||||
|
|
||||||
user ->
|
user ->
|
||||||
|
if user.confirmed_at do
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Welcome back!")
|
|> put_flash(:info, "Welcome back!")
|
||||||
|> UserAuth.log_in_user(user, user_params)
|
|> UserAuth.log_in_user(user, user_params)
|
||||||
|
else
|
||||||
|
{:ok, _} =
|
||||||
|
Accounts.deliver_user_confirmation_instructions(
|
||||||
|
user,
|
||||||
|
&url(~p"/users/confirm/#{&1}")
|
||||||
|
)
|
||||||
|
|
||||||
|
# In order to prevent user enumeration attacks, report the same error
|
||||||
|
# as invalid credentials.
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Invalid email, username or password")
|
||||||
|
|> put_flash(:email, String.slice(login, 0, 160))
|
||||||
|
|> redirect(to: ~p"/users/log-in")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -16,14 +16,11 @@ defmodule ChesstrainerWeb.EndgameLive.Form do
|
|||||||
<:subtitle>Use this form to manage endgame records in your database.</:subtitle>
|
<:subtitle>Use this form to manage endgame records in your database.</:subtitle>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<div class="field mb-6">
|
<div class="mb-6">
|
||||||
<label class="label">
|
<span class="mb-1 block text-sm font-medium text-base-content">Themes</span>
|
||||||
<span class="label-text">Themes</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div class="flex flex-wrap gap-2 mb-2">
|
<div class="flex flex-wrap gap-2 mb-2">
|
||||||
<%= for theme <- @selected_themes do %>
|
<.badge :for={theme <- @selected_themes} color="primary">
|
||||||
<span class="badge badge-primary gap-1">
|
|
||||||
{theme.name}
|
{theme.name}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -33,8 +30,7 @@ defmodule ChesstrainerWeb.EndgameLive.Form do
|
|||||||
>
|
>
|
||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</.badge>
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
@@ -42,30 +38,36 @@ defmodule ChesstrainerWeb.EndgameLive.Form do
|
|||||||
phx-change="search_themes"
|
phx-change="search_themes"
|
||||||
phx-submit="create_theme_from_search"
|
phx-submit="create_theme_from_search"
|
||||||
>
|
>
|
||||||
<input
|
<.input
|
||||||
type="text"
|
|
||||||
name="theme_search"
|
name="theme_search"
|
||||||
value={@theme_query}
|
value={@theme_query}
|
||||||
phx-debounce="200"
|
phx-debounce="200"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder="Search or create a theme…"
|
placeholder="Search or create a theme…"
|
||||||
class="input input-bordered w-full"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ul class="menu bg-base-100 rounded-box mt-2">
|
<ul class="mt-2 w-full rounded-md border border-base-300 bg-base-100 p-1 shadow-sm">
|
||||||
<%= for theme <- @theme_results do %>
|
<li :for={theme <- @theme_results}>
|
||||||
<li>
|
<button
|
||||||
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>{theme.name}</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>
|
</li>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= if @can_create do %>
|
<li :if={@can_create}>
|
||||||
<li>
|
<button
|
||||||
<button type="button" phx-click="create_theme" phx-value-name={@theme_query}>
|
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)}"
|
Create theme "{String.trim(@theme_query)}"
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
|
|||||||
label="Find by ID or FEN"
|
label="Find by ID or FEN"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder="Public code, database id, or FEN…"
|
placeholder="Public code, database id, or FEN…"
|
||||||
class="input input-bordered w-full"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<.button variant="primary">Find</.button>
|
<.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 :if={@search_query} id="endgame-search-results" class="space-y-3">
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<p class="text-sm text-base-content/70">Results for “{@search_query}”</p>
|
<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
|
Clear
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -49,7 +53,7 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
|
|||||||
No endgame matches “{@search_query}”.
|
No endgame matches “{@search_query}”.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table :if={@search_results != []} class="table table-zebra">
|
<table :if={@search_results != []} class={table_class()}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Key</th>
|
<th>Key</th>
|
||||||
@@ -115,11 +119,11 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
|
|||||||
{endgame.result}
|
{endgame.result}
|
||||||
</td>
|
</td>
|
||||||
<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}>
|
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>
|
||||||
{theme.name}
|
{theme.name}
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</.badge>
|
||||||
<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
|
<td
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
0} · Solved: {@endgame.times_solved || 0}<span :if={@user_rating}> · Your rating: {round(
|
0} · Solved: {@endgame.times_solved || 0}<span :if={@user_rating}> · Your rating: {round(
|
||||||
@user_rating
|
@user_rating
|
||||||
)}</span>
|
)}</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>
|
<span>FEN: {@endgame.fen}</span>
|
||||||
<button
|
<button
|
||||||
id="copy-fen-btn"
|
id="copy-fen-btn"
|
||||||
@@ -39,7 +39,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.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
|
<div
|
||||||
id="endgame-board"
|
id="endgame-board"
|
||||||
phx-hook="ChessBoard"
|
phx-hook="ChessBoard"
|
||||||
@@ -50,78 +50,78 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w-48 h-100 flex flex-col gap-3">
|
<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 %>
|
<%= cond do %>
|
||||||
<% @status == :loading -> %>
|
<% @status == :loading -> %>
|
||||||
<p class="text-gray-500">Loading tablebase…</p>
|
<p class="text-muted">Loading tablebase…</p>
|
||||||
<% @status == :blocked -> %>
|
<% @status == :blocked -> %>
|
||||||
<p class="font-semibold text-red-600">Tablebase unavailable</p>
|
<p class="font-semibold text-error">Tablebase unavailable</p>
|
||||||
<p class="text-red-500">{@blocked_reason}</p>
|
<p class="text-error">{@blocked_reason}</p>
|
||||||
<% @status == :solved -> %>
|
<% @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!"}
|
{if @endgame.result == :draw, do: "Draw held!", else: "Solved!"}
|
||||||
</p>
|
</p>
|
||||||
<% @status == :failed -> %>
|
<% @status == :failed -> %>
|
||||||
<p class="font-semibold text-red-600">Failed</p>
|
<p class="font-semibold text-error">Failed</p>
|
||||||
<p class="text-red-500">
|
<p class="text-error">
|
||||||
{if @endgame.result == :draw,
|
{if @endgame.result == :draw,
|
||||||
do: "That move loses the draw.",
|
do: "That move loses the draw.",
|
||||||
else: "That move throws away the win."}
|
else: "That move throws away the win."}
|
||||||
</p>
|
</p>
|
||||||
<%= if @best_move && @plies != [] do %>
|
<%= if @best_move && @plies != [] do %>
|
||||||
<p class="text-gray-600">
|
<p class="text-muted">
|
||||||
You played {List.last(@plies).san}; best was: {@best_move}
|
You played {List.last(@plies).san}; best was: {@best_move}
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% @awaiting_reply -> %>
|
<% @awaiting_reply -> %>
|
||||||
<p class="text-gray-500">Opponent is replying…</p>
|
<p class="text-muted">Opponent is replying…</p>
|
||||||
<% @last_grade == :optimal -> %>
|
<% @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 -> %>
|
<% @last_grade == :winning -> %>
|
||||||
<p class="font-semibold text-amber-600">
|
<p class="font-semibold text-warning">
|
||||||
{if @endgame.result == :draw,
|
{if @endgame.result == :draw,
|
||||||
do: "Keeps the draw — but not the sharpest",
|
do: "Keeps the draw — but not the sharpest",
|
||||||
else: "Winning — but not the sharpest"}
|
else: "Winning — but not the sharpest"}
|
||||||
</p>
|
</p>
|
||||||
<% @last_grade == :losing -> %>
|
<% @last_grade == :losing -> %>
|
||||||
<p class="font-semibold text-red-600">
|
<p class="font-semibold text-error">
|
||||||
{if @endgame.result == :draw,
|
{if @endgame.result == :draw,
|
||||||
do: "Losing move — this loses the draw",
|
do: "Losing move — this loses the draw",
|
||||||
else: "Losing move — this throws away the win"}
|
else: "Losing move — this throws away the win"}
|
||||||
</p>
|
</p>
|
||||||
<% @last_grade == :unknown -> %>
|
<% @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 -> %>
|
<% 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 %>
|
<% end %>
|
||||||
</div>
|
</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 %>
|
<%= cond do %>
|
||||||
<% @review_blocked -> %>
|
<% @review_blocked -> %>
|
||||||
<p class="text-gray-500">Best move unavailable here</p>
|
<p class="text-muted">Best move unavailable here</p>
|
||||||
<p class="text-gray-400">{@review_blocked}</p>
|
<p class="text-muted">{@review_blocked}</p>
|
||||||
<% @review_tablebase -> %>
|
<% @review_tablebase -> %>
|
||||||
<p class="text-gray-600 font-semibold mb-1">Best move:</p>
|
<p class="text-muted font-semibold mb-1">Best move:</p>
|
||||||
<p class="text-emerald-600">{best_move_text(@review_tablebase) || "—"}</p>
|
<p class="text-success-text">{best_move_text(@review_tablebase) || "—"}</p>
|
||||||
<%= if played_ply = played_ply_at(@line, @review_index) do %>
|
<%= if played_ply = played_ply_at(@line, @review_index) do %>
|
||||||
<p class={["mt-1", grade_class(played_ply.grade)]}>Played: {played_ply.san}</p>
|
<p class={["mt-1", grade_class(played_ply.grade)]}>Played: {played_ply.san}</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% true -> %>
|
<% true -> %>
|
||||||
<p class="text-gray-500">No best move.</p>
|
<p class="text-muted">No best move.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</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) %>
|
<% 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">
|
<div class="flex-1 overflow-y-auto">
|
||||||
<%= if plies == [] do %>
|
<%= if plies == [] do %>
|
||||||
<p class="text-sm text-gray-500">No Moves</p>
|
<p class="text-sm text-muted">No Moves</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= for {[white_ply, black_ply], move_no} <- move_rows(plies, @endgame.color) do %>
|
<%= for {[white_ply, black_ply], move_no} <- move_rows(plies, @endgame.color) do %>
|
||||||
<div class="font-mono text-sm leading-6">
|
<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 %>
|
<%= if white_ply do %>
|
||||||
<.ply
|
<.ply
|
||||||
ply={white_ply}
|
ply={white_ply}
|
||||||
@@ -130,7 +130,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
result={@endgame.result}
|
result={@endgame.result}
|
||||||
/>
|
/>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span class="text-gray-900">...</span>
|
<span class="text-body">...</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if black_ply do %>
|
<%= if black_ply do %>
|
||||||
<.ply
|
<.ply
|
||||||
@@ -504,16 +504,16 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
end
|
end
|
||||||
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_class(ply), do: grade_class(ply.grade)
|
||||||
|
|
||||||
defp ply_title(%{best_line: true}, _result), do: "Best line"
|
defp ply_title(%{best_line: true}, _result), do: "Best line"
|
||||||
defp ply_title(ply, result), do: grade_label(ply.grade, result)
|
defp ply_title(ply, result), do: grade_label(ply.grade, result)
|
||||||
|
|
||||||
defp grade_class(:optimal), do: "text-emerald-600"
|
defp grade_class(:optimal), do: "text-success-text"
|
||||||
defp grade_class(:winning), do: "text-amber-600"
|
defp grade_class(:winning), do: "text-warning"
|
||||||
defp grade_class(:losing), do: "text-red-600"
|
defp grade_class(:losing), do: "text-error"
|
||||||
defp grade_class(_), do: "text-gray-900"
|
defp grade_class(_), do: "text-body"
|
||||||
|
|
||||||
defp grade_label(nil, _result), do: nil
|
defp grade_label(nil, _result), do: nil
|
||||||
defp grade_label(:optimal, _result), do: "Optimal move"
|
defp grade_label(:optimal, _result), do: "Optimal move"
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndex do
|
|||||||
{round(endgame.rating)}
|
{round(endgame.rating)}
|
||||||
</td>
|
</td>
|
||||||
<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}>
|
<button type="button" phx-click="add_theme" phx-value-id={theme.id}>
|
||||||
{theme.name}
|
{theme.name}
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</.badge>
|
||||||
<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 class="w-0 font-semibold">
|
<td class="w-0 font-semibold">
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ defmodule ChesstrainerWeb.UserLive.Login do
|
|||||||
<% else %>
|
<% else %>
|
||||||
Don't have an account? <.link
|
Don't have an account? <.link
|
||||||
navigate={~p"/users/register"}
|
navigate={~p"/users/register"}
|
||||||
class="font-semibold text-brand hover:underline"
|
class="font-semibold text-primary hover:underline"
|
||||||
phx-no-format
|
phx-no-format
|
||||||
>Sign up</.link> for an account now.
|
>Sign up</.link> for an account now.
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -47,13 +47,22 @@ defmodule ChesstrainerWeb.UserLive.Login do
|
|||||||
autocomplete="current-password"
|
autocomplete="current-password"
|
||||||
spellcheck="false"
|
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>
|
Log in and stay logged in <span aria-hidden="true">→</span>
|
||||||
</.button>
|
</.button>
|
||||||
<.button class="btn btn-primary btn-soft w-full mt-2">
|
<.button class="w-full mt-2">
|
||||||
Log in only this time
|
Log in only this time
|
||||||
</.button>
|
</.button>
|
||||||
</.form>
|
</.form>
|
||||||
|
|
||||||
|
<p class="text-center text-sm">
|
||||||
|
<.link
|
||||||
|
navigate={~p"/users/reset-password"}
|
||||||
|
class="font-semibold text-primary hover:underline"
|
||||||
|
>
|
||||||
|
Forgot your password?
|
||||||
|
</.link>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Layouts.app>
|
</Layouts.app>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ defmodule ChesstrainerWeb.UserLive.Registration do
|
|||||||
Register for an account
|
Register for an account
|
||||||
<:subtitle>
|
<:subtitle>
|
||||||
Already registered?
|
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
|
Log in
|
||||||
</.link>
|
</.link>
|
||||||
to your account now.
|
to your account now.
|
||||||
@@ -57,7 +57,7 @@ defmodule ChesstrainerWeb.UserLive.Registration do
|
|||||||
required
|
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
|
Create an account
|
||||||
</.button>
|
</.button>
|
||||||
</.form>
|
</.form>
|
||||||
@@ -81,10 +81,19 @@ defmodule ChesstrainerWeb.UserLive.Registration do
|
|||||||
@impl true
|
@impl true
|
||||||
def handle_event("save", %{"user" => user_params}, socket) do
|
def handle_event("save", %{"user" => user_params}, socket) do
|
||||||
case Accounts.register_user(user_params) do
|
case Accounts.register_user(user_params) do
|
||||||
{:ok, _user} ->
|
{:ok, user} ->
|
||||||
|
{:ok, _} =
|
||||||
|
Accounts.deliver_user_confirmation_instructions(
|
||||||
|
user,
|
||||||
|
&url(~p"/users/confirm/#{&1}")
|
||||||
|
)
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> put_flash(:info, "Account created successfully. Please log in.")
|
|> put_flash(
|
||||||
|
:info,
|
||||||
|
"An email with instructions for how to confirm your email address has been sent to your inbox."
|
||||||
|
)
|
||||||
|> push_navigate(to: ~p"/users/log-in")}
|
|> push_navigate(to: ~p"/users/log-in")}
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
defmodule ChesstrainerWeb.UserLive.ResetPassword do
|
||||||
|
use ChesstrainerWeb, :live_view
|
||||||
|
|
||||||
|
alias Chesstrainer.Accounts
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def render(assigns) do
|
||||||
|
~H"""
|
||||||
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
||||||
|
<div class="mx-auto max-w-sm space-y-4">
|
||||||
|
<div class="text-center">
|
||||||
|
<.header>
|
||||||
|
{@title}
|
||||||
|
<:subtitle>{@subtitle}</:subtitle>
|
||||||
|
</.header>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<.form for={@form} id="reset_password_form" phx-submit={@submit_event}>
|
||||||
|
<%= if @token do %>
|
||||||
|
<.input
|
||||||
|
field={@form[:password]}
|
||||||
|
type="password"
|
||||||
|
label="New password"
|
||||||
|
autocomplete="new-password"
|
||||||
|
spellcheck="false"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<.input
|
||||||
|
field={@form[:password_confirmation]}
|
||||||
|
type="password"
|
||||||
|
label="Confirm new password"
|
||||||
|
autocomplete="new-password"
|
||||||
|
spellcheck="false"
|
||||||
|
/>
|
||||||
|
<% else %>
|
||||||
|
<.input
|
||||||
|
field={@form[:email]}
|
||||||
|
type="email"
|
||||||
|
label="Email"
|
||||||
|
autocomplete="email"
|
||||||
|
spellcheck="false"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<.button variant="primary" class="w-full" phx-disable-with="Saving...">
|
||||||
|
{@submit_label}
|
||||||
|
</.button>
|
||||||
|
</.form>
|
||||||
|
|
||||||
|
<p class="text-center text-sm">
|
||||||
|
<.link
|
||||||
|
navigate={~p"/users/log-in"}
|
||||||
|
class="font-semibold text-primary hover:underline"
|
||||||
|
>
|
||||||
|
Back to log in
|
||||||
|
</.link>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Layouts.app>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def mount(%{"token" => token}, _session, socket) do
|
||||||
|
case Accounts.get_user_by_reset_password_token(token) do
|
||||||
|
nil ->
|
||||||
|
{:ok,
|
||||||
|
socket
|
||||||
|
|> put_flash(:error, "Reset password link is invalid or it has expired.")
|
||||||
|
|> push_navigate(to: ~p"/users/log-in")}
|
||||||
|
|
||||||
|
user ->
|
||||||
|
{:ok,
|
||||||
|
socket
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> assign(:token, token)
|
||||||
|
|> assign(:title, "Reset password")
|
||||||
|
|> assign(:subtitle, "Choose a new password for your account.")
|
||||||
|
|> assign(:submit_label, "Reset password")
|
||||||
|
|> assign(:submit_event, "submit_password")
|
||||||
|
|> assign(:form, to_form(%{"password" => ""}, as: "user"))}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mount(_params, _session, socket) do
|
||||||
|
{:ok,
|
||||||
|
socket
|
||||||
|
|> assign(:user, nil)
|
||||||
|
|> assign(:token, nil)
|
||||||
|
|> assign(:title, "Forgot your password?")
|
||||||
|
|> assign(:subtitle, "Enter your email and we'll send you reset instructions.")
|
||||||
|
|> assign(:submit_label, "Send reset instructions")
|
||||||
|
|> assign(:submit_event, "submit_email")
|
||||||
|
|> assign(:form, to_form(%{"email" => ""}, as: "user"))}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_event("submit_email", %{"user" => %{"email" => email}}, socket) do
|
||||||
|
if user = Accounts.get_user_by_email(String.trim(email)) do
|
||||||
|
Accounts.deliver_user_reset_password_instructions(
|
||||||
|
user,
|
||||||
|
&url(~p"/users/reset-password/#{&1}")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(
|
||||||
|
:info,
|
||||||
|
"If your email is in our system, you will receive instructions to reset your password shortly."
|
||||||
|
)
|
||||||
|
|> push_navigate(to: ~p"/users/log-in")}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("submit_password", %{"user" => user_params}, socket) do
|
||||||
|
case Accounts.reset_user_password(socket.assigns.user, user_params) do
|
||||||
|
{:ok, {_user, _expired_tokens}} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(:info, "Password reset successfully. Log in with your new password.")
|
||||||
|
|> push_navigate(to: ~p"/users/log-in")}
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
{:noreply, assign(socket, form: to_form(changeset, action: :insert))}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -28,7 +28,7 @@ defmodule ChesstrainerWeb.UserLive.Settings do
|
|||||||
<.button variant="primary" phx-disable-with="Changing...">Change Email</.button>
|
<.button variant="primary" phx-disable-with="Changing...">Change Email</.button>
|
||||||
</.form>
|
</.form>
|
||||||
|
|
||||||
<div class="divider" />
|
<hr class="my-6 border-base-200" />
|
||||||
|
|
||||||
<.form
|
<.form
|
||||||
for={@password_form}
|
for={@password_form}
|
||||||
@@ -66,7 +66,7 @@ defmodule ChesstrainerWeb.UserLive.Settings do
|
|||||||
</.button>
|
</.button>
|
||||||
</.form>
|
</.form>
|
||||||
|
|
||||||
<div class="divider" />
|
<hr class="my-6 border-base-200" />
|
||||||
|
|
||||||
<section id="delete_account" class="space-y-4">
|
<section id="delete_account" class="space-y-4">
|
||||||
<.header>
|
<.header>
|
||||||
@@ -79,15 +79,14 @@ defmodule ChesstrainerWeb.UserLive.Settings do
|
|||||||
Nothing can be recovered.
|
Nothing can be recovered.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<button
|
<.button
|
||||||
id="delete_account_button"
|
id="delete_account_button"
|
||||||
type="button"
|
variant="danger"
|
||||||
class="btn btn-error"
|
|
||||||
phx-click="delete_account"
|
phx-click="delete_account"
|
||||||
data-confirm="This permanently deletes your account and all of your data. Nothing can be recovered. Are you sure?"
|
data-confirm="This permanently deletes your account and all of your data. Nothing can be recovered. Are you sure?"
|
||||||
>
|
>
|
||||||
Delete my account
|
Delete my account
|
||||||
</button>
|
</.button>
|
||||||
</section>
|
</section>
|
||||||
</Layouts.app>
|
</Layouts.app>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -83,8 +83,12 @@ defmodule ChesstrainerWeb.Router do
|
|||||||
live "/endgames/:public_code/play", EndgameLive.Play, :play
|
live "/endgames/:public_code/play", EndgameLive.Play, :play
|
||||||
live "/users/register", UserLive.Registration, :new
|
live "/users/register", UserLive.Registration, :new
|
||||||
live "/users/log-in", UserLive.Login, :new
|
live "/users/log-in", UserLive.Login, :new
|
||||||
|
live "/users/reset-password", UserLive.ResetPassword, :new
|
||||||
|
live "/users/reset-password/:token", UserLive.ResetPassword, :edit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/users/confirm/:token", UserConfirmationController, :edit
|
||||||
|
|
||||||
post "/users/log-in", UserSessionController, :create
|
post "/users/log-in", UserSessionController, :create
|
||||||
delete "/users/log-out", UserSessionController, :delete
|
delete "/users/log-out", UserSessionController, :delete
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
defmodule Chesstrainer.Repo.Migrations.CreateDailyPuzzles do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:daily_puzzles) do
|
||||||
|
add :date, :date, null: false
|
||||||
|
|
||||||
|
add :endgame_id, references(:endgames, type: :binary_id, on_delete: :delete_all),
|
||||||
|
null: false
|
||||||
|
|
||||||
|
timestamps(type: :utc_datetime)
|
||||||
|
end
|
||||||
|
|
||||||
|
create unique_index(:daily_puzzles, [:date])
|
||||||
|
create index(:daily_puzzles, [:endgame_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -163,7 +163,7 @@ defmodule Chesstrainer.AccountsTest do
|
|||||||
assert "has already been taken" in errors_on(changeset).username
|
assert "has already been taken" in errors_on(changeset).username
|
||||||
end
|
end
|
||||||
|
|
||||||
test "registers users with a password, a confirmed account and default access" do
|
test "registers users with a password, an unconfirmed account and default access" do
|
||||||
email = unique_user_email()
|
email = unique_user_email()
|
||||||
username = unique_username()
|
username = unique_username()
|
||||||
|
|
||||||
@@ -174,12 +174,70 @@ defmodule Chesstrainer.AccountsTest do
|
|||||||
assert user.username == username
|
assert user.username == username
|
||||||
assert is_binary(user.hashed_password)
|
assert is_binary(user.hashed_password)
|
||||||
assert is_nil(user.password)
|
assert is_nil(user.password)
|
||||||
assert user.confirmed_at
|
assert is_nil(user.confirmed_at)
|
||||||
assert user.role == :member
|
assert user.role == :member
|
||||||
assert user.plan == :free
|
assert user.plan == :free
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "deliver_user_confirmation_instructions/2" do
|
||||||
|
setup do
|
||||||
|
%{user: unconfirmed_user_fixture()}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "sends token through notification", %{user: user} do
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_confirmation_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, token} = Base.url_decode64(token, padding: false)
|
||||||
|
assert user_token = Repo.get_by(UserToken, token: :crypto.hash(:sha256, token))
|
||||||
|
assert user_token.user_id == user.id
|
||||||
|
assert user_token.sent_to == user.email
|
||||||
|
assert user_token.context == "confirm"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not send instructions when the account is already confirmed", %{user: user} do
|
||||||
|
{:ok, user} = Repo.update(User.confirm_changeset(user))
|
||||||
|
|
||||||
|
assert Accounts.deliver_user_confirmation_instructions(user, fn _ -> "" end) ==
|
||||||
|
{:error, :already_confirmed}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "confirm_user/1" do
|
||||||
|
setup do
|
||||||
|
user = unconfirmed_user_fixture()
|
||||||
|
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_confirmation_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
%{user: user, token: token}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "confirms the user with a valid token", %{user: user, token: token} do
|
||||||
|
assert {:ok, %User{} = confirmed_user} = Accounts.confirm_user(token)
|
||||||
|
assert confirmed_user.id == user.id
|
||||||
|
assert confirmed_user.confirmed_at
|
||||||
|
refute Repo.get_by(UserToken, user_id: user.id, context: "confirm")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not confirm with an invalid token", %{user: user} do
|
||||||
|
assert Accounts.confirm_user("oops") == :error
|
||||||
|
assert is_nil(Repo.get!(User, user.id).confirmed_at)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not confirm if the token expired", %{user: user, token: token} do
|
||||||
|
{1, nil} = Repo.update_all(UserToken, set: [inserted_at: ~N[2020-01-01 00:00:00]])
|
||||||
|
|
||||||
|
assert Accounts.confirm_user(token) == :error
|
||||||
|
assert is_nil(Repo.get!(User, user.id).confirmed_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "change_user_registration/3" do
|
describe "change_user_registration/3" do
|
||||||
test "returns a user changeset" do
|
test "returns a user changeset" do
|
||||||
assert %Ecto.Changeset{} = changeset = Accounts.change_user_registration(%User{})
|
assert %Ecto.Changeset{} = changeset = Accounts.change_user_registration(%User{})
|
||||||
@@ -381,6 +439,95 @@ defmodule Chesstrainer.AccountsTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "deliver_user_reset_password_instructions/2" do
|
||||||
|
setup do
|
||||||
|
%{user: user_fixture()}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "sends token through notification", %{user: user} do
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, token} = Base.url_decode64(token, padding: false)
|
||||||
|
assert user_token = Repo.get_by(UserToken, token: :crypto.hash(:sha256, token))
|
||||||
|
assert user_token.user_id == user.id
|
||||||
|
assert user_token.sent_to == user.email
|
||||||
|
assert user_token.context == "reset_password"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "get_user_by_reset_password_token/1" do
|
||||||
|
setup do
|
||||||
|
user = user_fixture()
|
||||||
|
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
%{user: user, token: token}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns the user with a valid token", %{user: user, token: token} do
|
||||||
|
assert %User{id: id} = Accounts.get_user_by_reset_password_token(token)
|
||||||
|
assert id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns nil with an invalid token" do
|
||||||
|
refute Accounts.get_user_by_reset_password_token("oops")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns nil if the token expired", %{token: token} do
|
||||||
|
{1, nil} = Repo.update_all(UserToken, set: [inserted_at: ~N[2020-01-01 00:00:00]])
|
||||||
|
|
||||||
|
refute Accounts.get_user_by_reset_password_token(token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "reset_user_password/2" do
|
||||||
|
setup do
|
||||||
|
%{user: user_fixture()}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "updates the password", %{user: user} do
|
||||||
|
assert {:ok, {%User{} = updated_user, expired_tokens}} =
|
||||||
|
Accounts.reset_user_password(user, %{password: "new valid password"})
|
||||||
|
|
||||||
|
assert updated_user.id == user.id
|
||||||
|
assert expired_tokens == []
|
||||||
|
assert is_nil(updated_user.password)
|
||||||
|
assert Accounts.get_user_by_login_and_password(user.email, "new valid password")
|
||||||
|
refute Accounts.get_user_by_login_and_password(user.email, valid_user_password())
|
||||||
|
end
|
||||||
|
|
||||||
|
test "deletes all tokens for the given user", %{user: user} do
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, {_, _}} = Accounts.reset_user_password(user, %{password: "new valid password"})
|
||||||
|
|
||||||
|
refute Repo.get_by(UserToken, user_id: user.id)
|
||||||
|
refute Accounts.get_user_by_reset_password_token(token)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "validates the new password", %{user: user} do
|
||||||
|
assert {:error, changeset} =
|
||||||
|
Accounts.reset_user_password(user, %{
|
||||||
|
password: "not valid",
|
||||||
|
password_confirmation: "another"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
password: ["should be at least 12 character(s)"],
|
||||||
|
password_confirmation: ["does not match password"]
|
||||||
|
} = errors_on(changeset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "generate_user_session_token/1" do
|
describe "generate_user_session_token/1" do
|
||||||
setup do
|
setup do
|
||||||
%{user: user_fixture()}
|
%{user: user_fixture()}
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
defmodule Chesstrainer.DailyPuzzlesTest do
|
||||||
|
use Chesstrainer.DataCase
|
||||||
|
|
||||||
|
alias Chesstrainer.DailyPuzzles
|
||||||
|
alias Chesstrainer.DailyPuzzles.DailyPuzzle
|
||||||
|
alias Chesstrainer.Endgames
|
||||||
|
alias Chesstrainer.Endgames.Endgame
|
||||||
|
alias Chesstrainer.Repo
|
||||||
|
alias Ecto.Adapters.SQL.Sandbox
|
||||||
|
|
||||||
|
@kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
|
@kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
|
@kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
|
||||||
|
|
||||||
|
defp create_endgame!(fen) do
|
||||||
|
{:ok, endgame} =
|
||||||
|
Endgames.create_endgame(%{fen: fen, color: :white, result: :win, rating: 1500})
|
||||||
|
|
||||||
|
endgame
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns nil and persists nothing when there are no endgames" do
|
||||||
|
date = ~D[2026-01-01]
|
||||||
|
|
||||||
|
assert DailyPuzzles.for_date(date) == nil
|
||||||
|
assert Repo.get_by(DailyPuzzle, date: date) == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
test "persists one stable endgame for the day" do
|
||||||
|
endgame = create_endgame!(@kr)
|
||||||
|
date = ~D[2026-01-01]
|
||||||
|
|
||||||
|
assert DailyPuzzles.for_date(date).id == endgame.id
|
||||||
|
assert DailyPuzzles.for_date(date).id == endgame.id
|
||||||
|
|
||||||
|
assert %DailyPuzzle{endgame_id: endgame_id} = Repo.get_by(DailyPuzzle, date: date)
|
||||||
|
assert endgame_id == endgame.id
|
||||||
|
assert Repo.aggregate(DailyPuzzle, :count) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rotates through endgames across consecutive days" do
|
||||||
|
create_endgame!(@kr)
|
||||||
|
create_endgame!(@kr_other)
|
||||||
|
create_endgame!(@kq)
|
||||||
|
|
||||||
|
day = ~D[2026-01-01]
|
||||||
|
ids = for offset <- 0..2, do: DailyPuzzles.for_date(Date.add(day, offset)).id
|
||||||
|
|
||||||
|
assert length(Enum.uniq(ids)) == 3
|
||||||
|
end
|
||||||
|
|
||||||
|
test "falls back to an endgame when the eligible pool is exhausted" do
|
||||||
|
endgame = create_endgame!(@kr)
|
||||||
|
day = ~D[2026-01-01]
|
||||||
|
|
||||||
|
assert DailyPuzzles.for_date(day).id == endgame.id
|
||||||
|
assert DailyPuzzles.for_date(Date.add(day, 1)).id == endgame.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "concurrent first requests create a single assignment" do
|
||||||
|
date = ~D[2026-01-01]
|
||||||
|
fens = [@kr, @kr_other, @kq]
|
||||||
|
|
||||||
|
cleanup = fn ->
|
||||||
|
Sandbox.unboxed_run(Repo, fn ->
|
||||||
|
Repo.delete_all(from daily_puzzle in DailyPuzzle, where: daily_puzzle.date == ^date)
|
||||||
|
Repo.delete_all(from endgame in Endgame, where: endgame.fen in ^fens)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
# This test commits outside the sandbox so the worker tasks use real,
|
||||||
|
# separate connections and actually race on the unique date constraint.
|
||||||
|
cleanup.()
|
||||||
|
on_exit(cleanup)
|
||||||
|
|
||||||
|
endgame_ids =
|
||||||
|
Sandbox.unboxed_run(Repo, fn ->
|
||||||
|
for fen <- fens, do: create_endgame!(fen).id
|
||||||
|
end)
|
||||||
|
|
||||||
|
tasks =
|
||||||
|
for _ <- 1..8 do
|
||||||
|
Task.async(fn ->
|
||||||
|
receive do
|
||||||
|
:go -> :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
Sandbox.unboxed_run(Repo, fn -> DailyPuzzles.for_date(date).id end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
Enum.each(tasks, &send(&1.pid, :go))
|
||||||
|
assigned_ids = Task.await_many(tasks, 10_000)
|
||||||
|
|
||||||
|
assert [assigned_id] = Enum.uniq(assigned_ids)
|
||||||
|
assert assigned_id in endgame_ids
|
||||||
|
|
||||||
|
count =
|
||||||
|
Sandbox.unboxed_run(Repo, fn ->
|
||||||
|
Repo.aggregate(
|
||||||
|
from(daily_puzzle in DailyPuzzle, where: daily_puzzle.date == ^date),
|
||||||
|
:count
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert count == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,6 +5,12 @@ defmodule Chesstrainer.EndgamesTest do
|
|||||||
alias Chesstrainer.Endgames.Endgame
|
alias Chesstrainer.Endgames.Endgame
|
||||||
alias Chesstrainer.Themes
|
alias Chesstrainer.Themes
|
||||||
|
|
||||||
|
setup do
|
||||||
|
previous = Application.get_env(:chesstrainer, :curated_endgame_codes)
|
||||||
|
on_exit(fn -> Application.put_env(:chesstrainer, :curated_endgame_codes, previous) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
@kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
@kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
@kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
|
@kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
@kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
|
@kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
|
||||||
@@ -302,4 +308,76 @@ defmodule Chesstrainer.EndgamesTest do
|
|||||||
assert Endgames.list_key_groups(%{key: "KQ v K"}) == [{"KQ v K", 1}]
|
assert Endgames.list_key_groups(%{key: "KQ v K"}) == [{"KQ v K", 1}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "count_endgames/0" do
|
||||||
|
test "returns 0 when there are no endgames" do
|
||||||
|
assert Endgames.count_endgames() == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
test "counts every stored endgame" do
|
||||||
|
create_endgame!(@kr)
|
||||||
|
create_endgame!(@kq)
|
||||||
|
|
||||||
|
assert Endgames.count_endgames() == 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "random_endgame/0" do
|
||||||
|
test "returns nil when there are no endgames" do
|
||||||
|
assert Endgames.random_endgame() == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns one of the existing endgames" do
|
||||||
|
kr = create_endgame!(@kr)
|
||||||
|
kq = create_endgame!(@kq)
|
||||||
|
|
||||||
|
assert Endgames.random_endgame().id in [kr.id, kq.id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "curated_endgames/1" do
|
||||||
|
test "returns the configured endgames in order with themes preloaded" do
|
||||||
|
{:ok, theme} = Themes.create_theme(%{name: "Opposition", category: :endgame})
|
||||||
|
first = create_endgame!(@kr, [theme])
|
||||||
|
second = create_endgame!(@kq)
|
||||||
|
|
||||||
|
Application.put_env(:chesstrainer, :curated_endgame_codes, [
|
||||||
|
first.public_code,
|
||||||
|
second.public_code
|
||||||
|
])
|
||||||
|
|
||||||
|
assert [one, two] = Endgames.curated_endgames(2)
|
||||||
|
assert one.id == first.id
|
||||||
|
assert two.id == second.id
|
||||||
|
assert Enum.map(one.themes, & &1.name) == ["Opposition"]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "fills missing or unresolved codes from the database" do
|
||||||
|
first = create_endgame!(@kr)
|
||||||
|
second = create_endgame!(@kq)
|
||||||
|
|
||||||
|
Application.put_env(:chesstrainer, :curated_endgame_codes, [first.public_code, "missing"])
|
||||||
|
|
||||||
|
endgames = Endgames.curated_endgames(2)
|
||||||
|
assert length(endgames) == 2
|
||||||
|
assert hd(endgames).id == first.id
|
||||||
|
assert Enum.any?(endgames, &(&1.id == second.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns a date-seeded selection when nothing is configured" do
|
||||||
|
first = create_endgame!(@kr)
|
||||||
|
second = create_endgame!(@kq)
|
||||||
|
|
||||||
|
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
|
||||||
|
|
||||||
|
ids = Endgames.curated_endgames(3) |> Enum.map(& &1.id)
|
||||||
|
assert Enum.sort(ids) == Enum.sort([first.id, second.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns an empty list when there are no endgames" do
|
||||||
|
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
|
||||||
|
|
||||||
|
assert Endgames.curated_endgames() == []
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -114,4 +114,35 @@ defmodule Chesstrainer.FENTest do
|
|||||||
assert FEN.piece_count(nil) == nil
|
assert FEN.piece_count(nil) == nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "board/1" do
|
||||||
|
test "returns eight ranks of eight squares" do
|
||||||
|
board = FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
||||||
|
|
||||||
|
assert length(board) == 8
|
||||||
|
assert Enum.all?(board, &(length(&1) == 8))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "expands empty-square digits into nil squares" do
|
||||||
|
assert FEN.board("8/8/8/8/8/8/8/8") ==
|
||||||
|
List.duplicate(List.duplicate(nil, 8), 8)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "maps each piece letter to its square" do
|
||||||
|
board = FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
||||||
|
|
||||||
|
assert Enum.at(board, 2) == [nil, nil, nil, "k", nil, nil, nil, nil]
|
||||||
|
assert Enum.at(board, 5) == [nil, nil, nil, "K", nil, "R", nil, nil]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reads only the board field" do
|
||||||
|
assert FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 37 99") ==
|
||||||
|
FEN.board("8/8/3k4/8/8/3K1R2/8/8")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns nil for a malformed board" do
|
||||||
|
assert FEN.board("not a fen") == nil
|
||||||
|
assert FEN.board(nil) == nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
defmodule ChesstrainerWeb.LandingComponentsTest do
|
||||||
|
use ChesstrainerWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
import Phoenix.LiveViewTest
|
||||||
|
|
||||||
|
alias Chesstrainer.Endgames.Endgame
|
||||||
|
alias Chesstrainer.Themes.Theme
|
||||||
|
alias ChesstrainerWeb.LandingComponents
|
||||||
|
|
||||||
|
@endgame %Endgame{
|
||||||
|
fen: "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1",
|
||||||
|
color: :white,
|
||||||
|
key: "KR v K"
|
||||||
|
}
|
||||||
|
|
||||||
|
test "renders the endgame's pieces, side to move, and caption" do
|
||||||
|
html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame})
|
||||||
|
|
||||||
|
assert html =~ "KR v K"
|
||||||
|
assert html =~ "To move"
|
||||||
|
assert html =~ "White"
|
||||||
|
assert html =~ "♔"
|
||||||
|
assert html =~ "♖"
|
||||||
|
assert html =~ "♚"
|
||||||
|
assert html =~ "Today’s position"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "falls back to a neutral position without an endgame" do
|
||||||
|
html = render_component(&LandingComponents.board_preview/1, %{endgame: nil})
|
||||||
|
|
||||||
|
assert html =~ "Featured position"
|
||||||
|
assert html =~ "White"
|
||||||
|
assert html =~ "♖"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders themes under the position title" do
|
||||||
|
endgame = %{
|
||||||
|
fen: @endgame.fen,
|
||||||
|
color: :white,
|
||||||
|
key: "KR v K",
|
||||||
|
themes: [%Theme{name: "Lucena"}]
|
||||||
|
}
|
||||||
|
|
||||||
|
html = render_component(&LandingComponents.board_preview/1, %{endgame: endgame})
|
||||||
|
|
||||||
|
assert html =~ "Lucena"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders the spark icon as a decorative primitive" do
|
||||||
|
html = render_component(&LandingComponents.icon_spark/1, %{})
|
||||||
|
|
||||||
|
assert html =~ "<svg"
|
||||||
|
assert html =~ ~s(aria-hidden="true")
|
||||||
|
assert html =~ "currentColor"
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "puzzle_count_label/1" do
|
||||||
|
test "shows counts below 100 exactly" do
|
||||||
|
assert LandingComponents.puzzle_count_label(0) == "0"
|
||||||
|
assert LandingComponents.puzzle_count_label(47) == "47"
|
||||||
|
assert LandingComponents.puzzle_count_label(99) == "99"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "floors counts of 100 or more to hundreds" do
|
||||||
|
assert LandingComponents.puzzle_count_label(100) == "100+"
|
||||||
|
assert LandingComponents.puzzle_count_label(199) == "100+"
|
||||||
|
assert LandingComponents.puzzle_count_label(999) == "900+"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "floors counts of 1000 or more to thousands" do
|
||||||
|
assert LandingComponents.puzzle_count_label(1000) == "1000+"
|
||||||
|
assert LandingComponents.puzzle_count_label(1999) == "1000+"
|
||||||
|
assert LandingComponents.puzzle_count_label(2400) == "2000+"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
defmodule ChesstrainerWeb.LayoutsTest do
|
||||||
|
use ChesstrainerWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
import Phoenix.LiveViewTest
|
||||||
|
|
||||||
|
alias ChesstrainerWeb.Layouts
|
||||||
|
|
||||||
|
describe "colour_mode_toggle/1" do
|
||||||
|
test "renders all three modes as a labelled radiogroup" do
|
||||||
|
html = render_component(&Layouts.colour_mode_toggle/1, %{})
|
||||||
|
|
||||||
|
assert html =~ ~s(role="radiogroup")
|
||||||
|
assert html =~ ~s(aria-label="Colour mode")
|
||||||
|
|
||||||
|
for {mode, label} <- [
|
||||||
|
{"system", "System colour mode"},
|
||||||
|
{"light", "Light colour mode"},
|
||||||
|
{"dark", "Dark colour mode"}
|
||||||
|
] do
|
||||||
|
assert html =~ ~s(data-phx-theme="#{mode}")
|
||||||
|
assert html =~ ~s(aria-label="#{label}")
|
||||||
|
assert html =~ ~s(role="radio")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert html =~ ~s(aria-checked="true")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "is rendered by the navbar" do
|
||||||
|
html = render_component(&Layouts.navbar/1, %{current_scope: nil})
|
||||||
|
|
||||||
|
assert html =~ ~s(aria-label="Colour mode")
|
||||||
|
assert html =~ ~s(class="nav-right")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,8 +1,186 @@
|
|||||||
defmodule ChesstrainerWeb.PageControllerTest do
|
defmodule ChesstrainerWeb.PageControllerTest do
|
||||||
use ChesstrainerWeb.ConnCase
|
use ChesstrainerWeb.ConnCase
|
||||||
|
|
||||||
test "GET /", %{conn: conn} do
|
import Chesstrainer.AccountsFixtures
|
||||||
conn = get(conn, ~p"/")
|
|
||||||
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
|
alias Chesstrainer.DailyPuzzles
|
||||||
|
alias Chesstrainer.Endgames
|
||||||
|
alias Chesstrainer.Themes
|
||||||
|
|
||||||
|
@fen_kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
|
@fen_kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
|
@fen_kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
|
||||||
|
|
||||||
|
setup do
|
||||||
|
previous = Application.get_env(:chesstrainer, :curated_endgame_codes)
|
||||||
|
on_exit(fn -> Application.put_env(:chesstrainer, :curated_endgame_codes, previous) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
defp create_endgame(fen, rating, theme_name) do
|
||||||
|
{:ok, theme} = Themes.create_theme(%{name: theme_name, category: :endgame})
|
||||||
|
|
||||||
|
{:ok, endgame} =
|
||||||
|
Endgames.create_endgame(%{fen: fen, color: :white, result: :win, rating: rating}, [theme])
|
||||||
|
|
||||||
|
endgame
|
||||||
|
end
|
||||||
|
|
||||||
|
defp curated! do
|
||||||
|
beginner = create_endgame(@fen_kr, 1500, "Opposition")
|
||||||
|
intermediate = create_endgame(@fen_kr_other, 1800, "Lucena")
|
||||||
|
advanced = create_endgame(@fen_kq, 2100, "Philidor")
|
||||||
|
|
||||||
|
Application.put_env(:chesstrainer, :curated_endgame_codes, [
|
||||||
|
beginner.public_code,
|
||||||
|
intermediate.public_code,
|
||||||
|
advanced.public_code
|
||||||
|
])
|
||||||
|
|
||||||
|
{beginner, intermediate, advanced}
|
||||||
|
end
|
||||||
|
|
||||||
|
@description "Short, focused endgame puzzles against tablebase-perfect defence. " <>
|
||||||
|
"Learn to see the winning move and make the endgame your strongest phase."
|
||||||
|
|
||||||
|
test "GET / renders the landing page, navbar, and footer", %{conn: conn} do
|
||||||
|
html = conn |> get(~p"/") |> html_response(200)
|
||||||
|
document = LazyHTML.from_document(html)
|
||||||
|
|
||||||
|
assert html =~ "Learn to see the"
|
||||||
|
assert html =~ "LUCID"
|
||||||
|
assert html =~ "Method"
|
||||||
|
assert html =~ "Puzzles"
|
||||||
|
assert html =~ "Start training"
|
||||||
|
assert html =~ ~s(id="nav-links")
|
||||||
|
assert html =~ "menu-button"
|
||||||
|
assert html =~ ~s(class="site-footer")
|
||||||
|
assert html =~ "© #{DateTime.utc_now().year} Lucid Chess"
|
||||||
|
assert html =~ ~p"/endgames"
|
||||||
|
assert html =~ "/assets/js/marketing.js"
|
||||||
|
refute html =~ "/assets/js/app.js"
|
||||||
|
|
||||||
|
assert LazyHTML.text(LazyHTML.query(document, "title")) =~ "Lucid Chess — Endgame Trainer"
|
||||||
|
refute html =~ "Phoenix Framework"
|
||||||
|
|
||||||
|
eyebrow = LazyHTML.query(document, ".eyebrow")
|
||||||
|
assert LazyHTML.text(eyebrow) =~ "Endgames, made clear"
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(eyebrow, "svg"), "aria-hidden") == ["true"]
|
||||||
|
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, ~s(meta[name="description"])), "content") ==
|
||||||
|
[@description]
|
||||||
|
|
||||||
|
assert [canonical] =
|
||||||
|
LazyHTML.attribute(LazyHTML.query(document, ~s(link[rel="canonical"])), "href")
|
||||||
|
|
||||||
|
assert URI.parse(canonical).path == "/"
|
||||||
|
|
||||||
|
for {selector, content} <- [
|
||||||
|
{~s(meta[property="og:type"]), "website"},
|
||||||
|
{~s(meta[property="og:site_name"]), "Lucid Chess"},
|
||||||
|
{~s(meta[property="og:title"]), "Lucid Chess — Endgame Trainer"},
|
||||||
|
{~s(meta[property="og:description"]), @description},
|
||||||
|
{~s(meta[property="og:url"]), canonical},
|
||||||
|
{~s(meta[name="twitter:card"]), "summary"},
|
||||||
|
{~s(meta[name="twitter:title"]), "Lucid Chess — Endgame Trainer"},
|
||||||
|
{~s(meta[name="twitter:description"]), @description}
|
||||||
|
] do
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, selector), "content") == [content]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "guest navbar links to log in and register", %{conn: conn} do
|
||||||
|
html = conn |> get(~p"/") |> html_response(200)
|
||||||
|
|
||||||
|
assert html =~ ~p"/users/log-in"
|
||||||
|
assert html =~ ~p"/users/register"
|
||||||
|
refute html =~ ~p"/users/settings"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "signed-in navbar links to settings and log out", %{conn: conn} do
|
||||||
|
html =
|
||||||
|
conn
|
||||||
|
|> log_in_user(user_fixture())
|
||||||
|
|> get(~p"/")
|
||||||
|
|> html_response(200)
|
||||||
|
|
||||||
|
assert html =~ ~p"/users/settings"
|
||||||
|
assert html =~ ~p"/users/log-out"
|
||||||
|
refute html =~ ~p"/users/register"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders curated cards and the daily board", %{conn: conn} do
|
||||||
|
{beginner, intermediate, advanced} = curated!()
|
||||||
|
daily = DailyPuzzles.today()
|
||||||
|
|
||||||
|
html = conn |> get(~p"/") |> html_response(200)
|
||||||
|
document = LazyHTML.from_document(html)
|
||||||
|
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, ".puzzle-card"), "href") == [
|
||||||
|
"/endgames/#{beginner.public_code}/play",
|
||||||
|
"/endgames/#{intermediate.public_code}/play",
|
||||||
|
"/endgames/#{advanced.public_code}/play"
|
||||||
|
]
|
||||||
|
|
||||||
|
board = LazyHTML.text(LazyHTML.query(document, ".board-caption"))
|
||||||
|
assert board =~ daily.key
|
||||||
|
|
||||||
|
for theme <- daily.themes do
|
||||||
|
assert board =~ theme.name
|
||||||
|
end
|
||||||
|
|
||||||
|
assert LazyHTML.text(LazyHTML.query(document, ".board-topline")) =~ "White"
|
||||||
|
assert html =~ "Try today's puzzle"
|
||||||
|
assert html =~ "Begin with the basics"
|
||||||
|
assert html =~ "<span>puzzles</span>"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hero and progress CTAs link to the daily puzzle", %{conn: conn} do
|
||||||
|
curated!()
|
||||||
|
daily = DailyPuzzles.today()
|
||||||
|
|
||||||
|
html = conn |> get(~p"/") |> html_response(200)
|
||||||
|
document = LazyHTML.from_document(html)
|
||||||
|
play_path = "/endgames/#{daily.public_code}/play"
|
||||||
|
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [play_path]
|
||||||
|
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, ".progress-banner a"), "href") == [
|
||||||
|
play_path
|
||||||
|
]
|
||||||
|
|
||||||
|
refute html =~ "/endgames//play"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows the same daily puzzle across requests", %{conn: conn} do
|
||||||
|
curated!()
|
||||||
|
daily = DailyPuzzles.today()
|
||||||
|
|
||||||
|
first = conn |> get(~p"/") |> html_response(200)
|
||||||
|
second = conn |> get(~p"/") |> html_response(200)
|
||||||
|
|
||||||
|
for html <- [first, second] do
|
||||||
|
board = LazyHTML.text(LazyHTML.query(LazyHTML.from_document(html), ".board-caption"))
|
||||||
|
assert board =~ daily.key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders without endgames", %{conn: conn} do
|
||||||
|
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
|
||||||
|
|
||||||
|
html = conn |> get(~p"/") |> html_response(200)
|
||||||
|
document = LazyHTML.from_document(html)
|
||||||
|
|
||||||
|
assert html =~ "Featured position"
|
||||||
|
assert html =~ "<span>puzzles</span>"
|
||||||
|
refute html =~ "puzzle-card"
|
||||||
|
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
|
||||||
|
"/endgames"
|
||||||
|
]
|
||||||
|
|
||||||
|
assert LazyHTML.attribute(LazyHTML.query(document, ".progress-banner a"), "href") == [
|
||||||
|
"/endgames"
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
defmodule ChesstrainerWeb.UserConfirmationControllerTest do
|
||||||
|
use ChesstrainerWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
import Chesstrainer.AccountsFixtures
|
||||||
|
|
||||||
|
alias Chesstrainer.Accounts
|
||||||
|
alias Chesstrainer.Accounts.User
|
||||||
|
alias Chesstrainer.Repo
|
||||||
|
|
||||||
|
setup do
|
||||||
|
%{user: unconfirmed_user_fixture()}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET /users/confirm/:token" do
|
||||||
|
test "confirms the user and redirects to the login page", %{conn: conn, user: user} do
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_confirmation_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
conn = get(conn, ~p"/users/confirm/#{token}")
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) == "User confirmed successfully."
|
||||||
|
assert redirected_to(conn) == ~p"/users/log-in"
|
||||||
|
assert Repo.get!(User, user.id).confirmed_at
|
||||||
|
end
|
||||||
|
|
||||||
|
test "redirects with an error for an invalid token", %{conn: conn} do
|
||||||
|
conn = get(conn, ~p"/users/confirm/oops")
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
|
||||||
|
"User not found or token is invalid."
|
||||||
|
|
||||||
|
assert redirected_to(conn) == ~p"/users/register"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -2,6 +2,7 @@ defmodule ChesstrainerWeb.UserSessionControllerTest do
|
|||||||
use ChesstrainerWeb.ConnCase, async: true
|
use ChesstrainerWeb.ConnCase, async: true
|
||||||
|
|
||||||
import Chesstrainer.AccountsFixtures
|
import Chesstrainer.AccountsFixtures
|
||||||
|
import Swoosh.TestAssertions
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
%{user: user_fixture()}
|
%{user: user_fixture()}
|
||||||
@@ -75,6 +76,25 @@ defmodule ChesstrainerWeb.UserSessionControllerTest do
|
|||||||
|
|
||||||
assert redirected_to(conn) == ~p"/users/log-in"
|
assert redirected_to(conn) == ~p"/users/log-in"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not log in an unconfirmed user and resends confirmation instructions", %{
|
||||||
|
conn: conn
|
||||||
|
} do
|
||||||
|
user = unconfirmed_user_fixture()
|
||||||
|
|
||||||
|
conn =
|
||||||
|
post(conn, ~p"/users/log-in", %{
|
||||||
|
"user" => %{"email" => user.email, "password" => valid_user_password()}
|
||||||
|
})
|
||||||
|
|
||||||
|
refute get_session(conn, :user_token)
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
|
||||||
|
"Invalid email, username or password"
|
||||||
|
|
||||||
|
assert redirected_to(conn) == ~p"/users/log-in"
|
||||||
|
assert_email_sent(subject: "Confirmation instructions")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "DELETE /users/log-out" do
|
describe "DELETE /users/log-out" do
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ defmodule ChesstrainerWeb.EndgameLive.IndexTest do
|
|||||||
|
|
||||||
assert html =~ "max-w-7xl"
|
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-count-K-v-K", "2")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "trims the table to the key columns", %{conn: conn} do
|
test "trims the table to the key columns", %{conn: conn} do
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndexTest do
|
|||||||
|
|
||||||
assert html =~ "Endgames"
|
assert html =~ "Endgames"
|
||||||
assert html =~ "max-w-7xl"
|
assert html =~ "max-w-7xl"
|
||||||
|
assert html =~ "/assets/js/app.js"
|
||||||
|
refute html =~ "/assets/js/marketing.js"
|
||||||
assert has_element?(view, "#key-group-K-v-K")
|
assert has_element?(view, "#key-group-K-v-K")
|
||||||
refute html =~ "Lucena"
|
refute html =~ "Lucena"
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ defmodule ChesstrainerWeb.EndgameLive.ShowTest do
|
|||||||
|
|
||||||
{:ok, view, _html} = live(conn, ~p"/admin/endgames/#{endgame.id}")
|
{:ok, view, _html} = live(conn, ~p"/admin/endgames/#{endgame.id}")
|
||||||
|
|
||||||
assert has_element?(view, "li.list-row", "Public code")
|
assert has_element?(view, "li", "Public code")
|
||||||
assert has_element?(view, "li.list-row", endgame.public_code)
|
assert has_element?(view, "#public-code", endgame.public_code)
|
||||||
assert has_element?(view, "h1", endgame.id)
|
assert has_element?(view, "h1", endgame.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ defmodule ChesstrainerWeb.UserLive.RegistrationTest do
|
|||||||
|
|
||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest
|
||||||
import Chesstrainer.AccountsFixtures
|
import Chesstrainer.AccountsFixtures
|
||||||
|
import Swoosh.TestAssertions
|
||||||
|
|
||||||
describe "Registration page" do
|
describe "Registration page" do
|
||||||
test "renders registration page", %{conn: conn} do
|
test "renders registration page", %{conn: conn} do
|
||||||
@@ -56,7 +57,10 @@ defmodule ChesstrainerWeb.UserLive.RegistrationTest do
|
|||||||
render_submit(form)
|
render_submit(form)
|
||||||
|> follow_redirect(conn, ~p"/users/log-in")
|
|> follow_redirect(conn, ~p"/users/log-in")
|
||||||
|
|
||||||
assert html =~ "Account created successfully"
|
assert html =~
|
||||||
|
"An email with instructions for how to confirm your email address has been sent to your inbox."
|
||||||
|
|
||||||
|
assert_email_sent(subject: "Confirmation instructions")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders errors for duplicated email", %{conn: conn} do
|
test "renders errors for duplicated email", %{conn: conn} do
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
defmodule ChesstrainerWeb.UserLive.ResetPasswordTest do
|
||||||
|
use ChesstrainerWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
import Phoenix.LiveViewTest
|
||||||
|
import Chesstrainer.AccountsFixtures
|
||||||
|
import Swoosh.TestAssertions
|
||||||
|
|
||||||
|
alias Chesstrainer.Accounts
|
||||||
|
|
||||||
|
describe "forgot password" do
|
||||||
|
test "renders the form", %{conn: conn} do
|
||||||
|
{:ok, _lv, html} = live(conn, ~p"/users/reset-password")
|
||||||
|
|
||||||
|
assert html =~ "Forgot your password?"
|
||||||
|
assert html =~ "Send reset instructions"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "sends reset instructions for a known email", %{conn: conn} do
|
||||||
|
user = user_fixture()
|
||||||
|
{:ok, lv, _html} = live(conn, ~p"/users/reset-password")
|
||||||
|
|
||||||
|
form = form(lv, "#reset_password_form", user: %{"email" => user.email})
|
||||||
|
|
||||||
|
{:ok, _lv, html} =
|
||||||
|
render_submit(form)
|
||||||
|
|> follow_redirect(conn, ~p"/users/log-in")
|
||||||
|
|
||||||
|
assert html =~ "If your email is in our system"
|
||||||
|
assert_email_sent(to: user.email, subject: "Reset password instructions")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not reveal an unknown email", %{conn: conn} do
|
||||||
|
{:ok, lv, _html} = live(conn, ~p"/users/reset-password")
|
||||||
|
|
||||||
|
form = form(lv, "#reset_password_form", user: %{"email" => "unknown@example.com"})
|
||||||
|
|
||||||
|
{:ok, _lv, html} =
|
||||||
|
render_submit(form)
|
||||||
|
|> follow_redirect(conn, ~p"/users/log-in")
|
||||||
|
|
||||||
|
assert html =~ "If your email is in our system"
|
||||||
|
refute_email_sent()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "reset password" do
|
||||||
|
setup do
|
||||||
|
user = user_fixture()
|
||||||
|
|
||||||
|
token =
|
||||||
|
extract_user_token(fn url ->
|
||||||
|
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
%{user: user, token: token}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders the form with a valid token", %{conn: conn, token: token} do
|
||||||
|
{:ok, _lv, html} = live(conn, ~p"/users/reset-password/#{token}")
|
||||||
|
|
||||||
|
assert html =~ "Reset password"
|
||||||
|
assert html =~ "Confirm new password"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "redirects with an error for an invalid token", %{conn: conn} do
|
||||||
|
{:ok, _lv, html} =
|
||||||
|
live(conn, ~p"/users/reset-password/oops")
|
||||||
|
|> follow_redirect(conn, ~p"/users/log-in")
|
||||||
|
|
||||||
|
assert html =~ "Reset password link is invalid or it has expired."
|
||||||
|
end
|
||||||
|
|
||||||
|
test "resets the password and redirects to log in", %{conn: conn, user: user, token: token} do
|
||||||
|
{:ok, lv, _html} = live(conn, ~p"/users/reset-password/#{token}")
|
||||||
|
|
||||||
|
form =
|
||||||
|
form(lv, "#reset_password_form",
|
||||||
|
user: %{
|
||||||
|
"password" => "new valid password",
|
||||||
|
"password_confirmation" => "new valid password"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
{:ok, _lv, html} =
|
||||||
|
render_submit(form)
|
||||||
|
|> follow_redirect(conn, ~p"/users/log-in")
|
||||||
|
|
||||||
|
assert html =~ "Password reset successfully"
|
||||||
|
|
||||||
|
assert Accounts.get_user_by_login_and_password(user.email, "new valid password")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows validation errors for mismatched passwords", %{conn: conn, token: token} do
|
||||||
|
{:ok, lv, _html} = live(conn, ~p"/users/reset-password/#{token}")
|
||||||
|
|
||||||
|
html =
|
||||||
|
lv
|
||||||
|
|> form("#reset_password_form",
|
||||||
|
user: %{
|
||||||
|
"password" => "new valid password",
|
||||||
|
"password_confirmation" => "something else"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
assert html =~ "does not match password"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -22,6 +22,17 @@ defmodule Chesstrainer.AccountsFixtures do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def user_fixture(attrs \\ %{}) do
|
def user_fixture(attrs \\ %{}) do
|
||||||
|
user = unconfirmed_user_fixture(attrs)
|
||||||
|
|
||||||
|
{:ok, user} =
|
||||||
|
user
|
||||||
|
|> Chesstrainer.Accounts.User.confirm_changeset()
|
||||||
|
|> Chesstrainer.Repo.update()
|
||||||
|
|
||||||
|
user
|
||||||
|
end
|
||||||
|
|
||||||
|
def unconfirmed_user_fixture(attrs \\ %{}) do
|
||||||
{:ok, user} =
|
{:ok, user} =
|
||||||
attrs
|
attrs
|
||||||
|> valid_user_attributes()
|
|> valid_user_attributes()
|
||||||
|
|||||||
Reference in New Issue
Block a user