mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cae4e35a70 | ||
|
|
5b3241ae1f | ||
|
|
805c2f1150 | ||
|
|
8df7ac982c
|
@@ -0,0 +1,7 @@
|
|||||||
|
SECRET_KEY_BASE=...
|
||||||
|
DATABASE_URL=...
|
||||||
|
PHX_HOST=innersquare.app
|
||||||
|
PORT=4000
|
||||||
|
SES_REGION=eu-north-1
|
||||||
|
SES_ACCESS_KEY_ID=AKIA...
|
||||||
|
SES_SECRET_ACCESS_KEY=...
|
||||||
@@ -16,6 +16,10 @@
|
|||||||
}
|
}
|
||||||
button, a { -webkit-tap-highlight-color: transparent; }
|
button, a { -webkit-tap-highlight-color: transparent; }
|
||||||
button { cursor: pointer; }
|
button { cursor: pointer; }
|
||||||
|
|
||||||
|
/* A consistent focus ring for links, buttons and native controls. Components
|
||||||
|
that provide their own ring (form inputs) override this through utilities. */
|
||||||
|
:focus-visible { outline: 2px solid var(--color-coral-text); outline-offset: 2px; }
|
||||||
}
|
}
|
||||||
|
|
||||||
main { overflow: hidden; flex: 1 0 auto; }
|
main { overflow: hidden; flex: 1 0 auto; }
|
||||||
|
|||||||
@@ -10,8 +10,11 @@
|
|||||||
--color-coral: var(--coral);
|
--color-coral: var(--coral);
|
||||||
--color-coral-control: var(--coral);
|
--color-coral-control: var(--coral);
|
||||||
--color-coral-control-hover: var(--coral-dark);
|
--color-coral-control-hover: var(--coral-dark);
|
||||||
--color-coral-text: var(--coral-dark);
|
--color-coral-text: #b8432c;
|
||||||
--color-success-text: var(--mint-deep);
|
--color-success-text: #3f6d5a;
|
||||||
|
--color-warning-text: #8a5a00;
|
||||||
|
--color-primary-text: #b8432c;
|
||||||
|
--color-error-text: #b8432c;
|
||||||
--color-mint-chip: var(--mint);
|
--color-mint-chip: var(--mint);
|
||||||
--color-on-accent-muted: #5f2c23;
|
--color-on-accent-muted: #5f2c23;
|
||||||
|
|
||||||
@@ -71,6 +74,9 @@ html[data-theme="dark"] {
|
|||||||
--color-coral-control-hover: #b8432c;
|
--color-coral-control-hover: #b8432c;
|
||||||
--color-coral-text: #ff9c85;
|
--color-coral-text: #ff9c85;
|
||||||
--color-success-text: #8fd3b5;
|
--color-success-text: #8fd3b5;
|
||||||
|
--color-warning-text: #f0b35a;
|
||||||
|
--color-primary-text: #f2816b;
|
||||||
|
--color-error-text: #f2816b;
|
||||||
--color-mint-chip: #24403a;
|
--color-mint-chip: #24403a;
|
||||||
--color-on-accent-muted: rgba(255, 255, 255, 0.97);
|
--color-on-accent-muted: rgba(255, 255, 255, 0.97);
|
||||||
--color-promotion-surface: #1b2822;
|
--color-promotion-surface: #1b2822;
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ h1 em { color: var(--color-coral); font-weight: 400; }
|
|||||||
|
|
||||||
.settings-subtitle {
|
.settings-subtitle {
|
||||||
font-size: 1rem;;
|
font-size: 1rem;;
|
||||||
color: var(--color-base-content);
|
color: var(--color-muted);
|
||||||
opacity: 0.7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 650px) {
|
@media (max-width: 650px) {
|
||||||
|
|||||||
@@ -39,3 +39,10 @@
|
|||||||
/* Admin Chessboard */
|
/* Admin Chessboard */
|
||||||
.bg-boardwhite { background-color: #f2f5f3; /* light square */ }
|
.bg-boardwhite { background-color: #f2f5f3; /* light square */ }
|
||||||
.bg-boardblack { background-color: #71828f; /* dark square */ }
|
.bg-boardblack { background-color: #71828f; /* dark square */ }
|
||||||
|
|
||||||
|
/* Play board */
|
||||||
|
#endgame-board { position: relative; }
|
||||||
|
|
||||||
|
/* Chessground's wrapper has no intrinsic height; let it fill the sized
|
||||||
|
aspect-ratio container so the board scales with the viewport. */
|
||||||
|
#endgame-board .cg-wrap { width: 100%; height: 100%; }
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
.mailing-list-copy p { margin-top: 16px; color: var(--color-on-deep-muted); font-size: 14px; line-height: 1.65; }
|
.mailing-list-copy p { margin-top: 16px; color: var(--color-on-deep-muted); font-size: 14px; line-height: 1.65; }
|
||||||
|
|
||||||
.mailing-list-form { width: min(420px, 100%); flex-shrink: 0; }
|
.mailing-list-form { width: min(420px, 100%); flex-shrink: 0; }
|
||||||
|
.mailing-list-honeypot { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
|
||||||
.mailing-list-form label { display: block; margin-bottom: 8px; color: var(--color-on-deep-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .11em; }
|
.mailing-list-form label { display: block; margin-bottom: 8px; color: var(--color-on-deep-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .11em; }
|
||||||
.mailing-list-row { display: flex; gap: 10px; }
|
.mailing-list-row { display: flex; gap: 10px; }
|
||||||
.mailing-list-row input { flex: 1; min-width: 0; padding: 15px 17px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 8px; background: rgba(255, 255, 255, .1); color: var(--color-on-deep); font-size: 14px; }
|
.mailing-list-row input { flex: 1; min-width: 0; padding: 15px 17px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 8px; background: rgba(255, 255, 255, .1); color: var(--color-on-deep); font-size: 14px; }
|
||||||
|
|||||||
@@ -22,7 +22,20 @@ export const ChessBoard = {
|
|||||||
this.applyBestLineMove({ from, to, promotion, san });
|
this.applyBestLineMove({ from, to, promotion, san });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.handleEvent("apply_move", ({ from, to, promotion }) => {
|
||||||
|
if (this.reviewing) return;
|
||||||
|
this.executeMove(from, to, promotion);
|
||||||
|
});
|
||||||
|
|
||||||
this.handleKeyDown = (event) => {
|
this.handleKeyDown = (event) => {
|
||||||
|
if (this.pendingPromotion) {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
|
this.cancelPromotion();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.reviewing) return;
|
if (!this.reviewing) return;
|
||||||
|
|
||||||
if (event.key === "ArrowLeft") {
|
if (event.key === "ArrowLeft") {
|
||||||
@@ -31,6 +44,12 @@ export const ChessBoard = {
|
|||||||
} else if (event.key === "ArrowRight") {
|
} else if (event.key === "ArrowRight") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.pushEvent("review_next", {});
|
this.pushEvent("review_next", {});
|
||||||
|
} else if (event.key === "Home") {
|
||||||
|
event.preventDefault();
|
||||||
|
this.pushEvent("review_start", {});
|
||||||
|
} else if (event.key === "End") {
|
||||||
|
event.preventDefault();
|
||||||
|
this.pushEvent("review_end", {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -185,9 +204,13 @@ export const ChessBoard = {
|
|||||||
|
|
||||||
showPromotionDialog(orig, dest) {
|
showPromotionDialog(orig, dest) {
|
||||||
this.pendingPromotion = { orig, dest };
|
this.pendingPromotion = { orig, dest };
|
||||||
|
this.previousFocus = document.activeElement;
|
||||||
const color = this.chess.turn() === "w" ? "white" : "black";
|
const color = this.chess.turn() === "w" ? "white" : "black";
|
||||||
const overlay = document.createElement("div");
|
const overlay = document.createElement("div");
|
||||||
overlay.className = "promotion-overlay";
|
overlay.className = "promotion-overlay";
|
||||||
|
overlay.setAttribute("role", "dialog");
|
||||||
|
overlay.setAttribute("aria-modal", "true");
|
||||||
|
overlay.setAttribute("aria-label", "Choose a promotion piece");
|
||||||
const picker = document.createElement("div");
|
const picker = document.createElement("div");
|
||||||
picker.className = "promotion-picker";
|
picker.className = "promotion-picker";
|
||||||
const pieces = [
|
const pieces = [
|
||||||
@@ -198,22 +221,64 @@ export const ChessBoard = {
|
|||||||
];
|
];
|
||||||
pieces.forEach(({ type, code }) => {
|
pieces.forEach(({ type, code }) => {
|
||||||
const btn = document.createElement("button");
|
const btn = document.createElement("button");
|
||||||
|
btn.type = "button";
|
||||||
btn.className = `promotion-piece ${type} ${color}`;
|
btn.className = `promotion-piece ${type} ${color}`;
|
||||||
|
btn.setAttribute("aria-label", `Promote to ${type}`);
|
||||||
btn.addEventListener("click", () => this.completePromotion(code));
|
btn.addEventListener("click", () => this.completePromotion(code));
|
||||||
picker.appendChild(btn);
|
picker.appendChild(btn);
|
||||||
});
|
});
|
||||||
|
overlay.addEventListener("keydown", (event) => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
|
this.cancelPromotion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key !== "Tab") return;
|
||||||
|
|
||||||
|
const buttons = Array.from(picker.querySelectorAll("button"));
|
||||||
|
const first = buttons[0];
|
||||||
|
const last = buttons[buttons.length - 1];
|
||||||
|
|
||||||
|
if (event.shiftKey && document.activeElement === first) {
|
||||||
|
event.preventDefault();
|
||||||
|
last.focus();
|
||||||
|
} else if (!event.shiftKey && document.activeElement === last) {
|
||||||
|
event.preventDefault();
|
||||||
|
first.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
overlay.appendChild(picker);
|
overlay.appendChild(picker);
|
||||||
const boardContainer = this.el.closest(".shadow-inner");
|
const container = this.el.parentElement;
|
||||||
boardContainer.style.position = "relative";
|
container.style.position = "relative";
|
||||||
boardContainer.appendChild(overlay);
|
container.appendChild(overlay);
|
||||||
|
picker.querySelector("button")?.focus();
|
||||||
|
},
|
||||||
|
|
||||||
|
cancelPromotion() {
|
||||||
|
this.pendingPromotion = null;
|
||||||
|
const overlay = this.el.parentElement?.querySelector(".promotion-overlay");
|
||||||
|
if (overlay) overlay.remove();
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
|
||||||
|
restoreFocus() {
|
||||||
|
if (this.previousFocus instanceof HTMLElement) {
|
||||||
|
this.previousFocus.focus();
|
||||||
|
} else {
|
||||||
|
document.getElementById("move-input")?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.previousFocus = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
completePromotion(pieceType) {
|
completePromotion(pieceType) {
|
||||||
const { orig, dest } = this.pendingPromotion;
|
const { orig, dest } = this.pendingPromotion;
|
||||||
this.pendingPromotion = null;
|
this.pendingPromotion = null;
|
||||||
const picker = this.el.closest(".shadow-inner")?.querySelector(".promotion-overlay");
|
const picker = this.el.parentElement?.querySelector(".promotion-overlay");
|
||||||
if (picker) picker.remove();
|
if (picker) picker.remove();
|
||||||
this.executeMove(orig, dest, pieceType);
|
this.executeMove(orig, dest, pieceType);
|
||||||
|
document.getElementById("move-input")?.focus();
|
||||||
},
|
},
|
||||||
|
|
||||||
executeMove(orig, dest, promotion) {
|
executeMove(orig, dest, promotion) {
|
||||||
@@ -234,6 +299,7 @@ export const ChessBoard = {
|
|||||||
san: move.san,
|
san: move.san,
|
||||||
promotion: promotion || null,
|
promotion: promotion || null,
|
||||||
draw: this.chess.isDraw(),
|
draw: this.chess.isDraw(),
|
||||||
|
check: this.chess.isCheck(),
|
||||||
checkmate: this.chess.isCheckmate(),
|
checkmate: this.chess.isCheckmate(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -252,8 +318,14 @@ export const ChessBoard = {
|
|||||||
? { color: null, dests: new Map() }
|
? { color: null, dests: new Map() }
|
||||||
: { color: nextTurnColor, dests: this.getValidDests() },
|
: { color: nextTurnColor, dests: this.getValidDests() },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.ground.set({ fen: this.chess.fen() });
|
this.ground.set({ fen: this.chess.fen() });
|
||||||
|
this.pushEvent("move_input_error", {
|
||||||
|
message: "That move is not legal in this position.",
|
||||||
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -279,6 +351,7 @@ export const ChessBoard = {
|
|||||||
fen: this.chess.fen(),
|
fen: this.chess.fen(),
|
||||||
san: move.san,
|
san: move.san,
|
||||||
draw: this.chess.isDraw(),
|
draw: this.chess.isDraw(),
|
||||||
|
check: this.chess.isCheck(),
|
||||||
checkmate: this.chess.isCheckmate(),
|
checkmate: this.chess.isCheckmate(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-1
@@ -14,7 +14,8 @@ config :chesstrainer, :branding,
|
|||||||
name: "Inner Square Chess",
|
name: "Inner Square Chess",
|
||||||
wordmark: "INNERSQUARE",
|
wordmark: "INNERSQUARE",
|
||||||
tagline: "Endgame Trainer",
|
tagline: "Endgame Trainer",
|
||||||
support_email: "support@lucidchess.app"
|
support_email: "support@innersquare.app",
|
||||||
|
mail_from: "no-reply@innersquare.app"
|
||||||
|
|
||||||
config :chesstrainer, :scopes,
|
config :chesstrainer, :scopes,
|
||||||
user: [
|
user: [
|
||||||
|
|||||||
@@ -101,6 +101,18 @@ if config_env() == :prod do
|
|||||||
|
|
||||||
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
|
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
|
||||||
|
|
||||||
|
config :chesstrainer, Chesstrainer.Mailer,
|
||||||
|
adapter: Swoosh.Adapters.AmazonSES,
|
||||||
|
region:
|
||||||
|
System.get_env("SES_REGION") ||
|
||||||
|
raise("environment variable SES_REGION is missing"),
|
||||||
|
access_key:
|
||||||
|
System.get_env("SES_ACCESS_KEY_ID") ||
|
||||||
|
raise("environment variable SES_ACCESS_KEY_ID is missing"),
|
||||||
|
secret:
|
||||||
|
System.get_env("SES_SECRET_ACCESS_KEY") ||
|
||||||
|
raise("environment variable SES_SECRET_ACCESS_KEY is missing")
|
||||||
|
|
||||||
config :chesstrainer, Chesstrainer.Repo,
|
config :chesstrainer, Chesstrainer.Repo,
|
||||||
# ssl: true,
|
# ssl: true,
|
||||||
url: database_url,
|
url: database_url,
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
__SITE_ADDRESS__ {
|
||||||
|
root * /var/www/innersquare
|
||||||
|
encode zstd gzip
|
||||||
|
file_server
|
||||||
|
|
||||||
|
header {
|
||||||
|
X-Content-Type-Options nosniff
|
||||||
|
X-Frame-Options DENY
|
||||||
|
Referrer-Policy strict-origin-when-cross-origin
|
||||||
|
Permissions-Policy "geolocation=(), microphone=(), camera=()"
|
||||||
|
X-Robots-Tag "noindex, nofollow"
|
||||||
|
}
|
||||||
|
|
||||||
|
@immutable path /fonts/* /favicon.ico
|
||||||
|
header @immutable Cache-Control "public, max-age=31536000, immutable"
|
||||||
|
|
||||||
|
@html path / /index.html
|
||||||
|
header @html Cache-Control "no-cache"
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
# Static coming-soon page
|
||||||
|
|
||||||
|
A self-contained branding page for the domain while the gated app (#116) and
|
||||||
|
mail delivery (#84) are still outstanding. It needs no BEAM, no database, no
|
||||||
|
newsletter form, and no JavaScript — just static files and Caddy.
|
||||||
|
|
||||||
|
```
|
||||||
|
deploy/static/
|
||||||
|
├── index.html # page + inline CSS; uses the app's real brand tokens
|
||||||
|
├── fonts/ # DM Sans + DM Serif Display woff2 files
|
||||||
|
├── favicon.ico # copied from priv/static
|
||||||
|
├── Caddyfile # site block template; rendered by deploy.sh --caddy
|
||||||
|
├── deploy.sh # upload files; optional marked Caddy block
|
||||||
|
└── README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## Preview locally
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 -m http.server 8080 --directory deploy/static
|
||||||
|
# open http://localhost:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
The page is deliberately light-only — it uses the brand's paper palette
|
||||||
|
regardless of the visitor's OS theme. It references `/fonts/...` and
|
||||||
|
`/favicon.ico` from the site root, so preview it at the root (as above), not
|
||||||
|
by opening `index.html` directly.
|
||||||
|
|
||||||
|
## One-time VPS setup
|
||||||
|
|
||||||
|
1. **DNS** — point an `A` record (and `AAAA` if you have IPv6) for the domain
|
||||||
|
and `www` at the VPS.
|
||||||
|
2. **SSH user** — the deploy user needs passwordless `sudo` for the commands in
|
||||||
|
`deploy.sh`, or use your normal sudo-capable user (`VPS_USER=ubuntu`).
|
||||||
|
3. **Firewall** — allow SSH, 80 and 443. With UFW:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo ufw allow OpenSSH
|
||||||
|
sudo ufw allow 80/tcp
|
||||||
|
sudo ufw allow 443/tcp
|
||||||
|
sudo ufw enable
|
||||||
|
```
|
||||||
|
|
||||||
|
Also open 80/443 in your provider's security group if you have one.
|
||||||
|
4. **Caddy** — install from the official apt repository:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
|
||||||
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
|
||||||
|
| sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||||
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
|
||||||
|
| sudo tee /etc/apt/sources.list.d/caddy-stable.list
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y caddy
|
||||||
|
sudo systemctl enable --now caddy
|
||||||
|
```
|
||||||
|
|
||||||
|
Caddy obtains and renews the TLS certificate automatically once DNS points
|
||||||
|
at the VPS and ports 80/443 are reachable.
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
### Files only (default)
|
||||||
|
|
||||||
|
Use this when the site block is already in your Caddy config. The script
|
||||||
|
uploads the files and **never touches Caddy**.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
VPS_HOST=203.0.113.10 VPS_USER=ubuntu ./deploy/static/deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Re-run this to update the page.
|
||||||
|
|
||||||
|
### Let the script manage the Caddy block (`--caddy`)
|
||||||
|
|
||||||
|
Pass `--caddy` and a `SITE_ADDRESS` to have the script add or update the site
|
||||||
|
block:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
SITE_ADDRESS="innersquarechess.com, www.innersquarechess.com" \
|
||||||
|
VPS_HOST=203.0.113.10 \
|
||||||
|
VPS_USER=ubuntu \
|
||||||
|
./deploy/static/deploy.sh --caddy
|
||||||
|
```
|
||||||
|
|
||||||
|
The script edits only the region between these markers in `REMOTE_CADDYFILE`
|
||||||
|
(default `/etc/caddy/Caddyfile`):
|
||||||
|
|
||||||
|
```caddyfile
|
||||||
|
# BEGIN innersquare-coming-soon (managed by deploy/static/deploy.sh)
|
||||||
|
...
|
||||||
|
# END innersquare-coming-soon
|
||||||
|
```
|
||||||
|
|
||||||
|
It backs up the file, validates the whole config, restores the backup if
|
||||||
|
validation fails, and reloads Caddy. If the domain already appears in the file
|
||||||
|
**without** the markers — for example, a block added by hand — it refuses to
|
||||||
|
touch the file rather than risk duplicating the site.
|
||||||
|
|
||||||
|
### Single shared Caddyfile
|
||||||
|
|
||||||
|
If all your server blocks live in `/etc/caddy/Caddyfile` and the innersquare
|
||||||
|
block is already there, use the default files-only mode. Don't run `--caddy`
|
||||||
|
unless you remove the manual block first and want the script to own it.
|
||||||
|
|
||||||
|
### Dedicated file / import
|
||||||
|
|
||||||
|
You can point `REMOTE_CADDYFILE` at a dedicated file and add one import line to
|
||||||
|
the main Caddyfile:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
REMOTE_CADDYFILE=/etc/caddy/conf.d/innersquare.caddy \
|
||||||
|
SITE_ADDRESS=innersquarechess.com \
|
||||||
|
VPS_HOST=203.0.113.10 \
|
||||||
|
VPS_USER=ubuntu \
|
||||||
|
./deploy/static/deploy.sh --caddy
|
||||||
|
```
|
||||||
|
|
||||||
|
```caddyfile
|
||||||
|
import /etc/caddy/conf.d/*.caddy
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional overrides: `SSH_PORT`, `WEB_ROOT` (default `/var/www/innersquare`),
|
||||||
|
`REMOTE_CADDYFILE` (default `/etc/caddy/Caddyfile`).
|
||||||
|
|
||||||
|
## What this page deliberately does not do
|
||||||
|
|
||||||
|
- **No newsletter signup** — that waits on real mail delivery (#84) and the
|
||||||
|
gated app (#116).
|
||||||
|
- **No analytics, cookies, or JavaScript.**
|
||||||
|
- **No indexing** — `robots.txt` is absent and Caddy sends
|
||||||
|
`X-Robots-Tag: noindex, nofollow` plus the page has a robots meta tag.
|
||||||
|
|
||||||
|
## Replacing it later
|
||||||
|
|
||||||
|
When the Phoenix release lands (#117), either point Caddy's reverse proxy at
|
||||||
|
the app or remove this Caddy site block. Keep the static page around as an
|
||||||
|
instant fallback if a deploy goes wrong.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 152 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,691 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Inner Square Chess — Endgame Trainer</title>
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Short, focused endgame puzzles against tablebase-perfect defence. Learn to see the winning move and make the endgame your strongest phase."
|
||||||
|
/>
|
||||||
|
<meta name="robots" content="noindex, nofollow" />
|
||||||
|
<meta name="theme-color" content="#f4f0e6" />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:site_name" content="Inner Square Chess" />
|
||||||
|
<meta property="og:title" content="Inner Square Chess — Endgame Trainer" />
|
||||||
|
<meta
|
||||||
|
property="og:description"
|
||||||
|
content="Short, focused endgame puzzles against tablebase-perfect defence. Launching soon."
|
||||||
|
/>
|
||||||
|
<meta name="twitter:card" content="summary" />
|
||||||
|
<link rel="icon" href="/favicon.ico" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@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 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--ink: #17352d;
|
||||||
|
--ink-soft: #587068;
|
||||||
|
--paper: #f4f0e6;
|
||||||
|
--cream: #fffcf4;
|
||||||
|
--mint: #b9d7c9;
|
||||||
|
--coral: #ef755d;
|
||||||
|
--coral-dark: #d95d48;
|
||||||
|
--line: rgba(23, 53, 45, 0.15);
|
||||||
|
|
||||||
|
--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-text: #b8432c;
|
||||||
|
--color-mint-chip: var(--mint);
|
||||||
|
|
||||||
|
--color-board-light: #e9e1cc;
|
||||||
|
--color-board-dark: #81a996;
|
||||||
|
--color-piece-light: #fffdf5;
|
||||||
|
--color-piece-outline: #17352d;
|
||||||
|
|
||||||
|
color-scheme: light;
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
min-width: 320px;
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: 100dvh;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: var(--color-canvas);
|
||||||
|
color: var(--color-body);
|
||||||
|
font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid var(--color-coral-text);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
flex: 1 0 auto;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Navigation */
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 8px 14px;
|
||||||
|
border: 1px solid var(--color-hairline);
|
||||||
|
border-radius: 999px;
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status::before {
|
||||||
|
content: "";
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--color-coral);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hero */
|
||||||
|
.hero {
|
||||||
|
width: min(1180px, calc(100% - 48px));
|
||||||
|
min-height: 650px;
|
||||||
|
margin: 0 auto;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 0.91fr 1.09fr;
|
||||||
|
align-items: center;
|
||||||
|
gap: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-copy {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
padding: 74px 0 92px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eyebrow {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: var(--color-coral-text);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.14em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eyebrow::before {
|
||||||
|
content: "";
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--color-coral);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
max-width: 590px;
|
||||||
|
margin: 18px 0 0;
|
||||||
|
font-family: "DM Serif Display", Georgia, serif;
|
||||||
|
font-size: clamp(56px, 6vw, 87px);
|
||||||
|
font-weight: 400;
|
||||||
|
letter-spacing: -0.035em;
|
||||||
|
line-height: 0.93;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 em {
|
||||||
|
color: var(--color-coral);
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-copy > p {
|
||||||
|
max-width: 480px;
|
||||||
|
margin: 29px 0 0;
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 17px;
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-copy > .note {
|
||||||
|
margin-top: 20px;
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Board */
|
||||||
|
.board-stage {
|
||||||
|
position: relative;
|
||||||
|
min-height: 580px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.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, 0.25);
|
||||||
|
transform: rotate(1.5deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-topline,
|
||||||
|
.board-caption {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-topline {
|
||||||
|
padding: 1px 1px 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-piece {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
width: 31px;
|
||||||
|
height: 31px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--color-deep);
|
||||||
|
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;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player strong {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.piece-count {
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.square {
|
||||||
|
position: relative;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rank,
|
||||||
|
.file {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 3;
|
||||||
|
color: rgba(23, 53, 45, 0.65);
|
||||||
|
font-size: 7px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rank {
|
||||||
|
top: 3px;
|
||||||
|
left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file {
|
||||||
|
right: 4px;
|
||||||
|
bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.square.dark .rank,
|
||||||
|
.square.dark .file {
|
||||||
|
color: rgba(255, 255, 255, 0.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;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-caption strong {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-themes {
|
||||||
|
color: var(--color-coral-text) !important;
|
||||||
|
font-size: 8px !important;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
|
.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 {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-footer > small {
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-stage {
|
||||||
|
min-height: 620px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.nav-wrap,
|
||||||
|
.hero,
|
||||||
|
.site-footer {
|
||||||
|
width: calc(100% - 36px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-wrap {
|
||||||
|
height: 74px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
padding: 7px 10px;
|
||||||
|
font-size: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-copy {
|
||||||
|
padding: 65px 0 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-copy > p {
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: clamp(51px, 15vw, 68px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-stage {
|
||||||
|
min-height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coral-orbit {
|
||||||
|
width: 340px;
|
||||||
|
height: 340px;
|
||||||
|
right: -28%;
|
||||||
|
top: 65px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mint-orbit {
|
||||||
|
width: 170px;
|
||||||
|
height: 170px;
|
||||||
|
left: -8%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-shell {
|
||||||
|
width: min(390px, 92vw);
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.piece {
|
||||||
|
font-size: clamp(24px, 9vw, 38px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-footer {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="nav-wrap" aria-label="Main navigation">
|
||||||
|
<a class="brand" href="/" aria-label="Inner Square Chess home">
|
||||||
|
<span class="brand-mark" aria-hidden="true">♞</span>
|
||||||
|
<span>INNERSQUARE</span>
|
||||||
|
</a>
|
||||||
|
<span class="status">Launching soon</span>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main id="main-content">
|
||||||
|
<section class="hero">
|
||||||
|
<div class="hero-copy">
|
||||||
|
<span class="eyebrow">Endgame training, coming soon</span>
|
||||||
|
<h1>Master the <em>endgame.</em></h1>
|
||||||
|
<p>
|
||||||
|
Short, focused endgame puzzles against tablebase-perfect defence.
|
||||||
|
Learn to see the winning move and make the endgame your strongest
|
||||||
|
phase.
|
||||||
|
</p>
|
||||||
|
<p class="note">
|
||||||
|
We’re putting the finishing touches on the trainer.
|
||||||
|
Check back soon.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="board-stage">
|
||||||
|
<div class="coral-orbit" aria-hidden="true"></div>
|
||||||
|
<div class="mint-orbit" aria-hidden="true"></div>
|
||||||
|
|
||||||
|
<div class="board-shell">
|
||||||
|
<div class="board-topline">
|
||||||
|
<div class="player">
|
||||||
|
<span class="player-piece" aria-hidden="true">♚</span>
|
||||||
|
<span>
|
||||||
|
<small>To move</small>
|
||||||
|
<strong>White</strong>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span class="piece-count">3 pieces</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="chessboard"
|
||||||
|
role="img"
|
||||||
|
aria-label="Chess position: white king on d5, white rook on g3, black king on f7. White to move."
|
||||||
|
>
|
||||||
|
<div class="square light"><span class="rank">8</span></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
|
||||||
|
<div class="square dark"><span class="rank">7</span></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"><span class="piece black-piece" aria-hidden="true">♚</span></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
|
||||||
|
<div class="square light"><span class="rank">6</span></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
|
||||||
|
<div class="square dark"><span class="rank">5</span></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"><span class="piece white-piece" aria-hidden="true">♔</span></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
|
||||||
|
<div class="square light"><span class="rank">4</span></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
|
||||||
|
<div class="square dark"><span class="rank">3</span></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"><span class="piece white-piece" aria-hidden="true">♖</span></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
|
||||||
|
<div class="square light"><span class="rank">2</span></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
<div class="square light"></div>
|
||||||
|
<div class="square dark"></div>
|
||||||
|
|
||||||
|
<div class="square dark"><span class="rank">1</span><span class="file">a</span></div>
|
||||||
|
<div class="square light"><span class="file">b</span></div>
|
||||||
|
<div class="square dark"><span class="file">c</span></div>
|
||||||
|
<div class="square light"><span class="file">d</span></div>
|
||||||
|
<div class="square dark"><span class="file">e</span></div>
|
||||||
|
<div class="square light"><span class="file">f</span></div>
|
||||||
|
<div class="square dark"><span class="file">g</span></div>
|
||||||
|
<div class="square light"><span class="file">h</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="board-caption">
|
||||||
|
<div>
|
||||||
|
<span>Sample position</span>
|
||||||
|
<strong>King and rook vs king</strong>
|
||||||
|
<small class="board-themes">Rook endgame</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="site-footer">
|
||||||
|
<div class="footer-brand">
|
||||||
|
<a class="brand" href="/" aria-label="Inner Square Chess home">
|
||||||
|
<span class="brand-mark" aria-hidden="true">♞</span>
|
||||||
|
<span>INNERSQUARE</span>
|
||||||
|
</a>
|
||||||
|
<p>Short, focused endgame training.</p>
|
||||||
|
</div>
|
||||||
|
<small>© 2026 Inner Square Chess</small>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -7,6 +7,7 @@ defmodule Chesstrainer.Accounts do
|
|||||||
alias Chesstrainer.Repo
|
alias Chesstrainer.Repo
|
||||||
|
|
||||||
alias Chesstrainer.Accounts.{User, UserToken, UserNotifier}
|
alias Chesstrainer.Accounts.{User, UserToken, UserNotifier}
|
||||||
|
alias Chesstrainer.MailingList
|
||||||
|
|
||||||
## Database getters
|
## Database getters
|
||||||
|
|
||||||
@@ -207,6 +208,7 @@ defmodule Chesstrainer.Accounts do
|
|||||||
with {:ok, query} <- UserToken.verify_change_email_token_query(token, context),
|
with {:ok, query} <- UserToken.verify_change_email_token_query(token, context),
|
||||||
%UserToken{sent_to: email} <- Repo.one(query),
|
%UserToken{sent_to: email} <- Repo.one(query),
|
||||||
{:ok, user} <- Repo.update(User.email_changeset(user, %{email: email})),
|
{:ok, user} <- Repo.update(User.email_changeset(user, %{email: email})),
|
||||||
|
{:ok, _subscription} <- MailingList.update_subscriber_email(user, email),
|
||||||
{_count, _result} <-
|
{_count, _result} <-
|
||||||
Repo.delete_all(from(UserToken, where: [user_id: ^user.id, context: ^context])) do
|
Repo.delete_all(from(UserToken, where: [user_id: ^user.id, context: ^context])) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ defmodule Chesstrainer.Accounts.UserNotifier do
|
|||||||
email =
|
email =
|
||||||
new()
|
new()
|
||||||
|> to(recipient)
|
|> to(recipient)
|
||||||
|> from({Branding.name(), Branding.support_email()})
|
|> from({Branding.name(), Branding.mail_from()})
|
||||||
|> subject(subject)
|
|> subject(subject)
|
||||||
|> text_body(body)
|
|> text_body(body)
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ defmodule Chesstrainer.Branding do
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@defaults [
|
@defaults [
|
||||||
name: "Lucid Chess",
|
name: "Inner Square Chess",
|
||||||
wordmark: "LUCID",
|
wordmark: "INNERSQUARE",
|
||||||
tagline: "Endgame Trainer",
|
tagline: "Endgame Trainer",
|
||||||
support_email: "support@lucidchess.app"
|
support_email: "support@innersquare.app",
|
||||||
|
mail_from: "no-reply@innersquare.app"
|
||||||
]
|
]
|
||||||
|
|
||||||
@doc "The display name, e.g. `\"Lucid Chess\"`."
|
@doc "The display name, e.g. `\"Lucid Chess\"`."
|
||||||
@@ -23,9 +24,12 @@ defmodule Chesstrainer.Branding do
|
|||||||
@doc "The tagline appended to the home title, e.g. `\"Endgame Trainer\"`."
|
@doc "The tagline appended to the home title, e.g. `\"Endgame Trainer\"`."
|
||||||
def tagline, do: get(:tagline)
|
def tagline, do: get(:tagline)
|
||||||
|
|
||||||
@doc "The address shown in legal pages and used as the mailer `from`."
|
@doc "The support address shown in legal pages and used as the mailer reply-to."
|
||||||
def support_email, do: get(:support_email)
|
def support_email, do: get(:support_email)
|
||||||
|
|
||||||
|
@doc "The From address used for outgoing mail."
|
||||||
|
def mail_from, do: get(:mail_from)
|
||||||
|
|
||||||
@doc "The home-page title, e.g. `\"Lucid Chess — Endgame Trainer\"`."
|
@doc "The home-page title, e.g. `\"Lucid Chess — Endgame Trainer\"`."
|
||||||
def home_title, do: "#{name()} — #{tagline()}"
|
def home_title, do: "#{name()} — #{tagline()}"
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ defmodule Chesstrainer.MailingList do
|
|||||||
confirmed when the user's account is. A subscriber created from the landing
|
confirmed when the user's account is. A subscriber created from the landing
|
||||||
page has no user; one created from registration is linked to the user so
|
page has no user; one created from registration is linked to the user so
|
||||||
deleting the account also removes their address.
|
deleting the account also removes their address.
|
||||||
|
|
||||||
|
Unsubscribing sets `unsubscribed_at` instead of deleting the row, so the
|
||||||
|
address stays suppressed and is never emailed again unless it opts back in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
@@ -17,6 +20,8 @@ defmodule Chesstrainer.MailingList do
|
|||||||
alias Chesstrainer.MailingList.Subscriber
|
alias Chesstrainer.MailingList.Subscriber
|
||||||
alias Chesstrainer.Repo
|
alias Chesstrainer.Repo
|
||||||
|
|
||||||
|
@confirmation_cooldown_seconds 10 * 60
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Requests a subscription from the landing-page form.
|
Requests a subscription from the landing-page form.
|
||||||
|
|
||||||
@@ -42,7 +47,8 @@ defmodule Chesstrainer.MailingList do
|
|||||||
email = Ecto.Changeset.get_field(changeset, :email)
|
email = Ecto.Changeset.get_field(changeset, :email)
|
||||||
|
|
||||||
case Repo.get_by(Subscriber, email: email) do
|
case Repo.get_by(Subscriber, email: email) do
|
||||||
%Subscriber{confirmed_at: confirmed_at} when not is_nil(confirmed_at) ->
|
%Subscriber{confirmed_at: confirmed_at, unsubscribed_at: nil}
|
||||||
|
when not is_nil(confirmed_at) ->
|
||||||
{:ok, :already_subscribed}
|
{:ok, :already_subscribed}
|
||||||
|
|
||||||
%Subscriber{} ->
|
%Subscriber{} ->
|
||||||
@@ -75,20 +81,92 @@ defmodule Chesstrainer.MailingList do
|
|||||||
@doc """
|
@doc """
|
||||||
Confirms a subscription by email address.
|
Confirms a subscription by email address.
|
||||||
|
|
||||||
|
Confirming also clears a previous unsubscribe, so an address that opted out
|
||||||
|
can rejoin only by going through a fresh confirmation.
|
||||||
|
|
||||||
Returns `{:error, :not_found}` when the address is not on the list.
|
Returns `{:error, :not_found}` when the address is not on the list.
|
||||||
"""
|
"""
|
||||||
def confirm(email) when is_binary(email) do
|
def confirm(email) when is_binary(email) do
|
||||||
case Repo.get_by(Subscriber, email: String.trim(email)) do
|
case Repo.get_by(Subscriber, email: String.trim(email)) do
|
||||||
nil ->
|
nil -> {:error, :not_found}
|
||||||
{:error, :not_found}
|
%Subscriber{} = subscriber -> confirm_subscriber(subscriber)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
%Subscriber{confirmed_at: nil} = subscriber ->
|
@doc """
|
||||||
subscriber
|
Unsubscribes an address from the mailing list.
|
||||||
|> Ecto.Changeset.change(confirmed_at: DateTime.utc_now(:second))
|
|
||||||
|> Repo.update()
|
The row is kept so the address remains suppressed. Idempotent.
|
||||||
|
"""
|
||||||
|
def unsubscribe(email) when is_binary(email) do
|
||||||
|
case Repo.get_by(Subscriber, email: String.trim(email)) do
|
||||||
|
nil -> {:error, :not_found}
|
||||||
|
%Subscriber{} = subscriber -> mark_unsubscribed(subscriber)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Unsubscribes the address linked to the given user account.
|
||||||
|
"""
|
||||||
|
def unsubscribe_user(%User{} = user) do
|
||||||
|
case Repo.get_by(Subscriber, user_id: user.id) do
|
||||||
|
nil -> {:error, :not_found}
|
||||||
|
%Subscriber{} = subscriber -> mark_unsubscribed(subscriber)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "Returns true when the user has an active mailing-list subscription."
|
||||||
|
def user_subscribed?(%User{} = user) do
|
||||||
|
Subscriber
|
||||||
|
|> where(
|
||||||
|
[s],
|
||||||
|
s.user_id == ^user.id and not is_nil(s.confirmed_at) and is_nil(s.unsubscribed_at)
|
||||||
|
)
|
||||||
|
|> Repo.exists?()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Keeps a user's linked subscription in step with their account email.
|
||||||
|
|
||||||
|
Returns `{:ok, :no_subscription}` when the user was not on the list.
|
||||||
|
"""
|
||||||
|
def update_subscriber_email(%User{} = user, new_email) when is_binary(new_email) do
|
||||||
|
case Repo.get_by(Subscriber, user_id: user.id) do
|
||||||
|
nil ->
|
||||||
|
{:ok, :no_subscription}
|
||||||
|
|
||||||
%Subscriber{} = subscriber ->
|
%Subscriber{} = subscriber ->
|
||||||
{:ok, subscriber}
|
new_email = String.trim(new_email)
|
||||||
|
|
||||||
|
case Repo.get_by(Subscriber, email: new_email) do
|
||||||
|
# An anonymous row may already hold the new address. Remove it so the
|
||||||
|
# unique email constraint does not block the account email change,
|
||||||
|
# but keep its unsubscribe so moving an account email cannot opt an
|
||||||
|
# address back in.
|
||||||
|
%Subscriber{user_id: nil, unsubscribed_at: anonymous_unsubscribed_at} =
|
||||||
|
anonymous ->
|
||||||
|
Repo.delete!(anonymous)
|
||||||
|
|
||||||
|
changeset = Subscriber.changeset(subscriber, %{email: new_email})
|
||||||
|
|
||||||
|
changeset =
|
||||||
|
if anonymous_unsubscribed_at do
|
||||||
|
Ecto.Changeset.put_change(
|
||||||
|
changeset,
|
||||||
|
:unsubscribed_at,
|
||||||
|
subscriber.unsubscribed_at || anonymous_unsubscribed_at
|
||||||
|
)
|
||||||
|
else
|
||||||
|
changeset
|
||||||
|
end
|
||||||
|
|
||||||
|
Repo.update(changeset)
|
||||||
|
|
||||||
|
_other ->
|
||||||
|
subscriber
|
||||||
|
|> Subscriber.changeset(%{email: new_email})
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -103,16 +181,71 @@ defmodule Chesstrainer.MailingList do
|
|||||||
|
|
||||||
Subscriber
|
Subscriber
|
||||||
|> where([s], s.user_id == ^user.id and is_nil(s.confirmed_at))
|
|> where([s], s.user_id == ^user.id and is_nil(s.confirmed_at))
|
||||||
|> Repo.update_all(set: [confirmed_at: now, updated_at: now])
|
|> Repo.update_all(set: [confirmed_at: now, unsubscribed_at: nil, updated_at: now])
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Returns the number of confirmed addresses on the mailing list."
|
@doc "Returns the number of active addresses on the mailing list."
|
||||||
def count_confirmed_subscribers do
|
def count_confirmed_subscribers do
|
||||||
Subscriber
|
Subscriber
|
||||||
|> where([s], not is_nil(s.confirmed_at))
|
|> where([s], not is_nil(s.confirmed_at) and is_nil(s.unsubscribed_at))
|
||||||
|> Repo.aggregate(:count)
|
|> Repo.aggregate(:count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns true when a confirmation email may be sent to this address.
|
||||||
|
|
||||||
|
Addresses without a subscriber row are allowed, as are addresses that have
|
||||||
|
not received a confirmation recently. This stops a repeated submission from
|
||||||
|
turning into an email flood.
|
||||||
|
"""
|
||||||
|
def confirmation_allowed?(email) when is_binary(email) do
|
||||||
|
case Repo.get_by(Subscriber, email: String.trim(email)) do
|
||||||
|
nil ->
|
||||||
|
true
|
||||||
|
|
||||||
|
%Subscriber{confirmation_sent_at: nil} ->
|
||||||
|
true
|
||||||
|
|
||||||
|
%Subscriber{confirmation_sent_at: sent_at} ->
|
||||||
|
DateTime.diff(DateTime.utc_now(:second), sent_at, :second) >=
|
||||||
|
@confirmation_cooldown_seconds
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "Records that a confirmation email was sent to this address."
|
||||||
|
def mark_confirmation_sent(email) when is_binary(email) do
|
||||||
|
case Repo.get_by(Subscriber, email: String.trim(email)) do
|
||||||
|
nil ->
|
||||||
|
:ok
|
||||||
|
|
||||||
|
%Subscriber{} = subscriber ->
|
||||||
|
subscriber
|
||||||
|
|> Ecto.Changeset.change(confirmation_sent_at: DateTime.utc_now(:second))
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp confirm_subscriber(%Subscriber{} = subscriber) do
|
||||||
|
attrs =
|
||||||
|
if is_nil(subscriber.confirmed_at) do
|
||||||
|
%{confirmed_at: DateTime.utc_now(:second), unsubscribed_at: nil}
|
||||||
|
else
|
||||||
|
%{unsubscribed_at: nil}
|
||||||
|
end
|
||||||
|
|
||||||
|
subscriber
|
||||||
|
|> Ecto.Changeset.change(attrs)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp mark_unsubscribed(%Subscriber{unsubscribed_at: nil} = subscriber) do
|
||||||
|
subscriber
|
||||||
|
|> Ecto.Changeset.change(unsubscribed_at: DateTime.utc_now(:second))
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp mark_unsubscribed(%Subscriber{} = subscriber), do: {:ok, subscriber}
|
||||||
|
|
||||||
defp insert_subscription(changeset, email) do
|
defp insert_subscription(changeset, email) do
|
||||||
case Repo.insert(changeset) do
|
case Repo.insert(changeset) do
|
||||||
{:ok, _subscriber} ->
|
{:ok, _subscriber} ->
|
||||||
@@ -123,9 +256,15 @@ defmodule Chesstrainer.MailingList do
|
|||||||
# above and this insert; the unique constraint decides, so re-read it.
|
# above and this insert; the unique constraint decides, so re-read it.
|
||||||
if email_taken?(changeset) do
|
if email_taken?(changeset) do
|
||||||
case Repo.get_by(Subscriber, email: email) do
|
case Repo.get_by(Subscriber, email: email) do
|
||||||
%Subscriber{confirmed_at: nil} -> {:ok, :confirmation_required}
|
%Subscriber{confirmed_at: confirmed_at, unsubscribed_at: nil}
|
||||||
%Subscriber{} -> {:ok, :already_subscribed}
|
when not is_nil(confirmed_at) ->
|
||||||
nil -> {:error, changeset}
|
{:ok, :already_subscribed}
|
||||||
|
|
||||||
|
%Subscriber{} ->
|
||||||
|
{:ok, :confirmation_required}
|
||||||
|
|
||||||
|
nil ->
|
||||||
|
{:error, changeset}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{:error, changeset}
|
{:error, changeset}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ defmodule Chesstrainer.MailingList.Notifier do
|
|||||||
email =
|
email =
|
||||||
new()
|
new()
|
||||||
|> to(recipient)
|
|> to(recipient)
|
||||||
|> from({Branding.name(), Branding.support_email()})
|
|> from({Branding.name(), Branding.mail_from()})
|
||||||
|
|> reply_to(Branding.support_email())
|
||||||
|> subject(subject)
|
|> subject(subject)
|
||||||
|> text_body(body)
|
|> text_body(body)
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ defmodule Chesstrainer.MailingList.Subscriber do
|
|||||||
field :email, :string
|
field :email, :string
|
||||||
field :source, Ecto.Enum, values: [:home, :registration], default: :home
|
field :source, Ecto.Enum, values: [:home, :registration], default: :home
|
||||||
field :confirmed_at, :utc_datetime
|
field :confirmed_at, :utc_datetime
|
||||||
|
field :unsubscribed_at, :utc_datetime
|
||||||
|
field :confirmation_sent_at, :utc_datetime
|
||||||
belongs_to :user, User
|
belongs_to :user, User
|
||||||
|
|
||||||
timestamps(type: :utc_datetime)
|
timestamps(type: :utc_datetime)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ defmodule ChesstrainerWeb.Board.BoardComponent do
|
|||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
import ChesstrainerWeb.Board.SquareComponent
|
import ChesstrainerWeb.Board.SquareComponent
|
||||||
|
|
||||||
|
alias ChesstrainerWeb.Board.PositionText
|
||||||
|
|
||||||
attr :game, :map, required: true
|
attr :game, :map, required: true
|
||||||
|
|
||||||
attr :myself, :any, default: nil
|
attr :myself, :any, default: nil
|
||||||
@@ -41,7 +43,11 @@ defmodule ChesstrainerWeb.Board.BoardComponent do
|
|||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class={["m-auto left-0 right-0", @class]}>
|
<div class={["m-auto left-0 right-0", @class]}>
|
||||||
<div class="border border-2 border-zinc-700 grid grid-rows-8 grid-cols-8">
|
<div
|
||||||
|
class="border border-2 border-zinc-700 grid grid-rows-8 grid-cols-8"
|
||||||
|
role="img"
|
||||||
|
aria-label={"Chess position. #{PositionText.summary(Map.get(@game, :fen))}"}
|
||||||
|
>
|
||||||
<%= for rank <- @ranks do %>
|
<%= for rank <- @ranks do %>
|
||||||
<%= for file <- @files do %>
|
<%= for file <- @files do %>
|
||||||
<% square = {file, rank} %>
|
<% square = {file, rank} %>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ defmodule ChesstrainerWeb.Board.PieceComponent do
|
|||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<%= if @path do %>
|
<%= if @path do %>
|
||||||
<img src={@path} class={@class} />
|
<img src={@path} class={@class} alt="" aria-hidden="true" />
|
||||||
<% end %>
|
<% end %>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
defmodule ChesstrainerWeb.Board.PositionText do
|
||||||
|
@moduledoc """
|
||||||
|
Plain-language descriptions of a chess position for assistive technology.
|
||||||
|
|
||||||
|
A chessground board is a picture to a screen reader, so the play surface and
|
||||||
|
the static boards use this text as their accessible name or description.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias Chesstrainer.FEN
|
||||||
|
|
||||||
|
@files ~w(a b c d e f g h)
|
||||||
|
|
||||||
|
@names %{
|
||||||
|
"k" => "king",
|
||||||
|
"q" => "queen",
|
||||||
|
"r" => "rook",
|
||||||
|
"b" => "bishop",
|
||||||
|
"n" => "knight",
|
||||||
|
"p" => "pawn"
|
||||||
|
}
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Describes whose turn it is and where every piece stands.
|
||||||
|
|
||||||
|
Returns a generic description when the FEN cannot be read.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> ChesstrainerWeb.Board.PositionText.summary("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
||||||
|
"White to move. White: king on d3, rook on f3. Black: king on d6."
|
||||||
|
"""
|
||||||
|
@spec summary(String.t() | nil) :: String.t()
|
||||||
|
def summary(fen) when is_binary(fen) do
|
||||||
|
case FEN.board(fen) do
|
||||||
|
nil ->
|
||||||
|
"Chess position."
|
||||||
|
|
||||||
|
rows ->
|
||||||
|
["#{turn(fen)}." | piece_groups(rows)]
|
||||||
|
|> Enum.join(" ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def summary(_fen), do: "Chess position."
|
||||||
|
|
||||||
|
defp turn(fen) do
|
||||||
|
case FEN.color_from_fen(fen) do
|
||||||
|
:white -> "White to move"
|
||||||
|
:black -> "Black to move"
|
||||||
|
_ -> "Side to move unknown"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp piece_groups(rows) do
|
||||||
|
["White", "Black"]
|
||||||
|
|> Enum.map(fn label -> group(label, rows) end)
|
||||||
|
|> Enum.reject(&is_nil/1)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp group(label, rows) do
|
||||||
|
colour = if label == "White", do: :white, else: :black
|
||||||
|
|
||||||
|
case pieces(rows, colour) do
|
||||||
|
[] -> nil
|
||||||
|
pieces -> "#{label}: #{Enum.join(pieces, ", ")}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp pieces(rows, colour) do
|
||||||
|
rows
|
||||||
|
|> Enum.with_index()
|
||||||
|
|> Enum.flat_map(fn {row, rank_index} ->
|
||||||
|
row
|
||||||
|
|> Enum.with_index()
|
||||||
|
|> Enum.flat_map(fn
|
||||||
|
{nil, _file_index} ->
|
||||||
|
[]
|
||||||
|
|
||||||
|
{piece, file_index} ->
|
||||||
|
if piece_colour(piece) == colour do
|
||||||
|
square = "#{Enum.at(@files, file_index)}#{8 - rank_index}"
|
||||||
|
["#{Map.fetch!(@names, String.downcase(piece))} on #{square}"]
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp piece_colour(piece) do
|
||||||
|
if piece == String.upcase(piece), do: :white, else: :black
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -112,7 +112,7 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
<.button phx-click="go" variant="primary">Send!</.button>
|
<.button phx-click="go" variant="primary">Send!</.button>
|
||||||
<.button navigate={~p"/"}>Home</.button>
|
<.button navigate={~p"/"}>Home</.button>
|
||||||
"""
|
"""
|
||||||
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 type)
|
||||||
attr :class, :any
|
attr :class, :any
|
||||||
attr :variant, :string, values: ~w(primary secondary ghost danger)
|
attr :variant, :string, values: ~w(primary secondary ghost danger)
|
||||||
slot :inner_block, required: true
|
slot :inner_block, required: true
|
||||||
@@ -123,7 +123,7 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
"secondary" => "border border-base-300 bg-base-100 text-base-content hover:bg-base-200",
|
"secondary" => "border border-base-300 bg-base-100 text-base-content hover:bg-base-200",
|
||||||
"ghost" => "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",
|
"danger" => "bg-error text-error-content hover:bg-error/90",
|
||||||
nil => "bg-primary/15 text-primary hover:bg-primary/25"
|
nil => "bg-primary/15 text-primary-text hover:bg-primary/25"
|
||||||
}
|
}
|
||||||
|
|
||||||
assigns =
|
assigns =
|
||||||
@@ -338,7 +338,7 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
# Helper used by inputs to generate form errors
|
# Helper used by inputs to generate form errors
|
||||||
defp error(assigns) do
|
defp error(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<p class="mt-1.5 flex gap-2 items-center text-sm text-error">
|
<p class="mt-1.5 flex gap-2 items-center text-sm text-error-text">
|
||||||
<.icon name="hero-exclamation-circle" class="size-5" />
|
<.icon name="hero-exclamation-circle" class="size-5" />
|
||||||
{render_slot(@inner_block)}
|
{render_slot(@inner_block)}
|
||||||
</p>
|
</p>
|
||||||
@@ -479,8 +479,8 @@ defmodule ChesstrainerWeb.CoreComponents do
|
|||||||
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium",
|
"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]",
|
@size == "sm" && "px-1.5 text-[0.7rem]",
|
||||||
@color == "neutral" && "bg-base-200 text-base-content",
|
@color == "neutral" && "bg-base-200 text-base-content",
|
||||||
@color == "primary" && "bg-primary/15 text-primary",
|
@color == "primary" && "bg-primary/15 text-primary-text",
|
||||||
@color == "warning" && "bg-warning/15 text-warning",
|
@color == "warning" && "bg-warning/15 text-warning-text",
|
||||||
@class
|
@class
|
||||||
]}
|
]}
|
||||||
{@rest}
|
{@rest}
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ defmodule ChesstrainerWeb.EndgameList do
|
|||||||
phx-click="remove_theme"
|
phx-click="remove_theme"
|
||||||
phx-value-id={theme.id}
|
phx-value-id={theme.id}
|
||||||
aria-label={"Remove #{theme.name}"}
|
aria-label={"Remove #{theme.name}"}
|
||||||
|
class="px-1"
|
||||||
>
|
>
|
||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ defmodule ChesstrainerWeb.LandingComponents do
|
|||||||
|
|
||||||
alias Chesstrainer.FEN
|
alias Chesstrainer.FEN
|
||||||
alias Chesstrainer.Themes
|
alias Chesstrainer.Themes
|
||||||
|
alias ChesstrainerWeb.Board.PositionText
|
||||||
|
alias ChesstrainerWeb.MailingListFormToken
|
||||||
|
|
||||||
@button_variants %{
|
@button_variants %{
|
||||||
nav: "nav-cta",
|
nav: "nav-cta",
|
||||||
@@ -84,14 +86,27 @@ defmodule ChesstrainerWeb.LandingComponents do
|
|||||||
<section class="mailing-list" id="mailing-list">
|
<section class="mailing-list" id="mailing-list">
|
||||||
<div class="mailing-list-copy">
|
<div class="mailing-list-copy">
|
||||||
<span class="section-kicker">Mailing list</span>
|
<span class="section-kicker">Mailing list</span>
|
||||||
<h2>One good endgame idea, now and then.</h2>
|
<h2>Stay in the loop.</h2>
|
||||||
<p>
|
<p>
|
||||||
Occasional emails about new puzzles and features. We'll ask you to confirm your address first.
|
Get occasional endgame ideas, new puzzles, and feature updates delivered to your inbox. (Please confirm your email after signing up.)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form action="/mailing-list" method="post" id="mailing-list-form" class="mailing-list-form">
|
<form action="/mailing-list" method="post" id="mailing-list-form" class="mailing-list-form">
|
||||||
<input type="hidden" name="_csrf_token" value={get_csrf_token()} />
|
<input type="hidden" name="_csrf_token" value={get_csrf_token()} />
|
||||||
|
<input type="hidden" name="subscriber[form_token]" value={MailingListFormToken.sign()} />
|
||||||
|
|
||||||
|
<div class="mailing-list-honeypot" aria-hidden="true">
|
||||||
|
<label for="mailing-list-company">Company</label>
|
||||||
|
<input
|
||||||
|
id="mailing-list-company"
|
||||||
|
type="text"
|
||||||
|
name="subscriber[company]"
|
||||||
|
tabindex="-1"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label for="mailing-list-email">Email address</label>
|
<label for="mailing-list-email">Email address</label>
|
||||||
<div class="mailing-list-row">
|
<div class="mailing-list-row">
|
||||||
<input
|
<input
|
||||||
@@ -180,14 +195,21 @@ defmodule ChesstrainerWeb.LandingComponents do
|
|||||||
assigns = assign(assigns, :squares, squares)
|
assigns = assign(assigns, :squares, squares)
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class="chessboard" aria-label="Chess position">
|
<div
|
||||||
|
class="chessboard"
|
||||||
|
role="img"
|
||||||
|
aria-label={"Chess position. #{PositionText.summary(assigns.fen)}"}
|
||||||
|
>
|
||||||
<%= for square <- @squares do %>
|
<%= for square <- @squares do %>
|
||||||
<div class={[
|
<div
|
||||||
"square",
|
class={[
|
||||||
if(square.light, do: "light", else: "dark"),
|
"square",
|
||||||
square.selected? && "selected",
|
if(square.light, do: "light", else: "dark"),
|
||||||
square.target? && "target"
|
square.selected? && "selected",
|
||||||
]}>
|
square.target? && "target"
|
||||||
|
]}
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
<span :if={square.label_rank} class="rank">{square.rank}</span>
|
<span :if={square.label_rank} class="rank">{square.rank}</span>
|
||||||
<span :if={square.label_file} class="file">{square.file}</span>
|
<span :if={square.label_file} class="file">{square.file}</span>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ defmodule ChesstrainerWeb.Layouts do
|
|||||||
|
|
||||||
def app(assigns) do
|
def app(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<main class="px-4 py-20 sm:px-6 lg:px-8">
|
<main id="main-content" tabindex="-1" class="px-4 py-20 sm:px-6 lg:px-8">
|
||||||
<div class={["mx-auto space-y-4", if(@wide, do: "max-w-7xl", else: "max-w-2xl")]}>
|
<div class={["mx-auto space-y-4", if(@wide, do: "max-w-7xl", else: "max-w-2xl")]}>
|
||||||
{render_slot(@inner_block)}
|
{render_slot(@inner_block)}
|
||||||
</div>
|
</div>
|
||||||
@@ -235,7 +235,10 @@ defmodule ChesstrainerWeb.Layouts do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Provides the system / light / dark colour-mode switch.
|
Provides the light / dark colour-mode switch.
|
||||||
|
|
||||||
|
With no saved preference the page follows the OS setting; only the explicit
|
||||||
|
light and dark modes are selectable here.
|
||||||
|
|
||||||
The click handling and `aria-checked` syncing live in `theme_script.html.heex`,
|
The click handling and `aria-checked` syncing live in `theme_script.html.heex`,
|
||||||
which runs before paint and also on pages without LiveView (the landing page
|
which runs before paint and also on pages without LiveView (the landing page
|
||||||
@@ -250,40 +253,31 @@ defmodule ChesstrainerWeb.Layouts do
|
|||||||
aria-label="Colour mode"
|
aria-label="Colour mode"
|
||||||
>
|
>
|
||||||
<div
|
<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]"
|
class="absolute w-1/2 h-full rounded-full border border-base-200 bg-base-100 brightness-200 left-0 [[data-theme=dark]_&]:left-1/2 transition-[left]"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="flex p-2 cursor-pointer w-1/3 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
|
class="flex p-2 cursor-pointer w-1/2 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
|
||||||
data-phx-theme="system"
|
|
||||||
role="radio"
|
|
||||||
aria-checked="true"
|
|
||||||
aria-label="System colour mode"
|
|
||||||
>
|
|
||||||
<.icon name="hero-computer-desktop-micro" class="size-4 opacity-75 hover:opacity-100" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="flex p-2 cursor-pointer w-1/3 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
|
|
||||||
data-phx-theme="light"
|
data-phx-theme="light"
|
||||||
role="radio"
|
role="radio"
|
||||||
aria-checked="false"
|
aria-checked="true"
|
||||||
aria-label="Light colour mode"
|
aria-label="Light colour mode"
|
||||||
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<.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
|
||||||
type="button"
|
type="button"
|
||||||
class="flex p-2 cursor-pointer w-1/3 justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
|
class="flex p-2 cursor-pointer w-1/2 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"
|
role="radio"
|
||||||
aria-checked="false"
|
aria-checked="false"
|
||||||
aria-label="Dark colour mode"
|
aria-label="Dark colour mode"
|
||||||
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<.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>
|
||||||
|
|||||||
@@ -67,6 +67,12 @@
|
|||||||
<Layouts.theme_script />
|
<Layouts.theme_script />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<a
|
||||||
|
href="#main-content"
|
||||||
|
class="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-50 focus:rounded-md focus:bg-base-100 focus:px-4 focus:py-2 focus:text-base-content focus:shadow-lg"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
<Layouts.navbar current_scope={@current_scope} />
|
<Layouts.navbar current_scope={@current_scope} />
|
||||||
{@inner_content}
|
{@inner_content}
|
||||||
<Layouts.footer />
|
<Layouts.footer />
|
||||||
|
|||||||
@@ -16,14 +16,15 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectedMode = () => {
|
// There is no system button, so report the effective theme. This keeps the
|
||||||
const source = document.documentElement.getAttribute("data-theme-source");
|
// visible light/dark control in sync when the page is following the OS.
|
||||||
return source === "system" ? "system" : document.documentElement.getAttribute("data-theme");
|
const selectedMode = () => document.documentElement.getAttribute("data-theme");
|
||||||
};
|
|
||||||
|
|
||||||
const syncChecked = () => {
|
const syncChecked = () => {
|
||||||
document.querySelectorAll("[data-phx-theme]").forEach((button) => {
|
document.querySelectorAll("[data-phx-theme]").forEach((button) => {
|
||||||
button.setAttribute("aria-checked", String(button.dataset.phxTheme === selectedMode()));
|
const checked = button.dataset.phxTheme === selectedMode();
|
||||||
|
button.setAttribute("aria-checked", String(checked));
|
||||||
|
button.tabIndex = checked ? 0 : -1;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,6 +57,25 @@
|
|||||||
if (button) setMode(button.dataset.phxTheme);
|
if (button) setMode(button.dataset.phxTheme);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Arrow keys move between the radio options, as a radiogroup should.
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
const button = event.target instanceof Element && event.target.closest("[data-phx-theme]");
|
||||||
|
if (!button) return;
|
||||||
|
|
||||||
|
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
const buttons = Array.from(document.querySelectorAll("[data-phx-theme]"));
|
||||||
|
const offset = event.key === "ArrowRight" ? 1 : -1;
|
||||||
|
const index = (buttons.indexOf(button) + offset + buttons.length) % buttons.length;
|
||||||
|
const next = buttons[index];
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
setMode(next.dataset.phxTheme);
|
||||||
|
next.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener("storage", (event) => {
|
window.addEventListener("storage", (event) => {
|
||||||
if (event.key === "phx:theme") setMode(event.newValue || "system");
|
if (event.key === "phx:theme") setMode(event.newValue || "system");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
|
|
||||||
use ChesstrainerWeb, :html
|
use ChesstrainerWeb, :html
|
||||||
|
|
||||||
|
alias ChesstrainerWeb.Board.PositionText
|
||||||
alias ChesstrainerWeb.EndgameLive.PlayCore
|
alias ChesstrainerWeb.EndgameLive.PlayCore
|
||||||
|
|
||||||
attr :endgame, :any, required: true
|
attr :endgame, :any, required: true
|
||||||
|
attr :fen, :string, default: nil
|
||||||
attr :status, :atom, required: true
|
attr :status, :atom, required: true
|
||||||
attr :blocked_reason, :string, default: nil
|
attr :blocked_reason, :string, default: nil
|
||||||
attr :best_move, :string, default: nil
|
attr :best_move, :string, default: nil
|
||||||
@@ -24,26 +26,98 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
attr :last_grade, :atom, default: nil
|
attr :last_grade, :atom, default: nil
|
||||||
attr :awaiting_best_line, :boolean, default: false
|
attr :awaiting_best_line, :boolean, default: false
|
||||||
attr :session, :boolean, default: false
|
attr :session, :boolean, default: false
|
||||||
|
attr :move_input, :string, default: ""
|
||||||
|
attr :move_input_error, :string, default: nil
|
||||||
|
attr :last_check, :boolean, default: false
|
||||||
|
attr :last_checkmate, :boolean, default: false
|
||||||
|
|
||||||
def play_surface(assigns) do
|
def play_surface(assigns) do
|
||||||
|
assigns =
|
||||||
|
assigns
|
||||||
|
|> assign(
|
||||||
|
:can_input,
|
||||||
|
assigns.status == :playing and not assigns.awaiting_reply and not assigns.reviewing
|
||||||
|
)
|
||||||
|
|> assign(:move_hint, move_hint(assigns.status, assigns.awaiting_reply))
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class="flex gap-2 bg-base-200 p-4 rounded-xl shadow-inner">
|
<div class="flex flex-col gap-2 rounded-xl bg-base-200 p-4 shadow-inner sm:flex-row">
|
||||||
<div class="w-100 flex flex-col gap-2">
|
<div class="flex w-full flex-col gap-2 sm:w-100">
|
||||||
<div
|
<div class="relative">
|
||||||
id="endgame-board"
|
<div
|
||||||
phx-hook="ChessBoard"
|
id="endgame-board"
|
||||||
phx-update="ignore"
|
phx-hook="ChessBoard"
|
||||||
data-endgame-id={@endgame.id}
|
phx-update="ignore"
|
||||||
class="w-100 h-100"
|
data-endgame-id={@endgame.id}
|
||||||
>
|
class="aspect-square w-full"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div :if={@reviewing} id="review-controls" class="flex items-center gap-2">
|
<div
|
||||||
|
id="board-announcer"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
aria-atomic="true"
|
||||||
|
class="sr-only"
|
||||||
|
>
|
||||||
|
{board_announcement(assigns)}
|
||||||
|
</div>
|
||||||
|
<div id="position-summary" class="sr-only">
|
||||||
|
{PositionText.summary(position_fen(assigns))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
:if={not @reviewing}
|
||||||
|
id="move-input-form"
|
||||||
|
phx-submit="submit_move"
|
||||||
|
phx-change="move_input"
|
||||||
|
phx-debounce="200"
|
||||||
|
class="flex items-start gap-2"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<.input
|
||||||
|
id="move-input"
|
||||||
|
name="move"
|
||||||
|
value={@move_input}
|
||||||
|
label="Your move"
|
||||||
|
placeholder="Nf3 or g1f3"
|
||||||
|
autocomplete="off"
|
||||||
|
aria-describedby="move-input-help"
|
||||||
|
disabled={not @can_input}
|
||||||
|
class="font-mono"
|
||||||
|
/>
|
||||||
|
<p id="move-input-help" class="mt-1 text-xs text-muted">
|
||||||
|
SAN or UCI, e.g. <span class="font-mono">Nf3</span>
|
||||||
|
or <span class="font-mono">g1f3</span>.
|
||||||
|
</p>
|
||||||
|
<p :if={@move_hint} class="mt-1 text-xs text-muted" role="status">{@move_hint}</p>
|
||||||
|
<p
|
||||||
|
:if={@move_input_error}
|
||||||
|
id="move-input-error"
|
||||||
|
role="alert"
|
||||||
|
class="mt-1 text-sm text-error-text"
|
||||||
|
>
|
||||||
|
{@move_input_error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<.button type="submit" class="mt-6" disabled={not @can_input}>Play move</.button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div
|
||||||
|
:if={@reviewing}
|
||||||
|
id="review-controls"
|
||||||
|
class="flex items-center gap-2"
|
||||||
|
role="group"
|
||||||
|
aria-label="Review navigation"
|
||||||
|
>
|
||||||
<.button
|
<.button
|
||||||
id="review-start"
|
id="review-start"
|
||||||
phx-click="review_start"
|
phx-click="review_start"
|
||||||
disabled={@review_index <= 0}
|
disabled={@review_index <= 0}
|
||||||
title="Back to start"
|
title="Back to start"
|
||||||
|
aria-label="Back to start"
|
||||||
>
|
>
|
||||||
{"<<"}
|
{"<<"}
|
||||||
</.button>
|
</.button>
|
||||||
@@ -52,6 +126,7 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
phx-click="review_prev"
|
phx-click="review_prev"
|
||||||
disabled={@review_index <= 0}
|
disabled={@review_index <= 0}
|
||||||
title="Previous position"
|
title="Previous position"
|
||||||
|
aria-label="Previous position"
|
||||||
>
|
>
|
||||||
←
|
←
|
||||||
</.button>
|
</.button>
|
||||||
@@ -60,6 +135,7 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
phx-click="review_next"
|
phx-click="review_next"
|
||||||
disabled={@review_index >= length(@line)}
|
disabled={@review_index >= length(@line)}
|
||||||
title="Next position"
|
title="Next position"
|
||||||
|
aria-label="Next position"
|
||||||
>
|
>
|
||||||
→
|
→
|
||||||
</.button>
|
</.button>
|
||||||
@@ -68,12 +144,13 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
phx-click="review_end"
|
phx-click="review_end"
|
||||||
disabled={@review_index >= length(@line)}
|
disabled={@review_index >= length(@line)}
|
||||||
title="Go to end"
|
title="Go to end"
|
||||||
|
aria-label="Go to end"
|
||||||
>
|
>
|
||||||
{">>"}
|
{">>"}
|
||||||
</.button>
|
</.button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2" role="group" aria-label="Puzzle actions">
|
||||||
<.button
|
<.button
|
||||||
:if={(@reviewing and @review_tablebase) && PlayCore.best_move_text(@review_tablebase)}
|
:if={(@reviewing and @review_tablebase) && PlayCore.best_move_text(@review_tablebase)}
|
||||||
phx-click="play_best_line"
|
phx-click="play_best_line"
|
||||||
@@ -105,8 +182,8 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="relative w-48">
|
<div class="relative w-full sm:w-48">
|
||||||
<div class="absolute inset-0 flex flex-col gap-3">
|
<div class="flex flex-col gap-3 sm:absolute sm:inset-0">
|
||||||
<%= if @reviewing do %>
|
<%= if @reviewing do %>
|
||||||
<div
|
<div
|
||||||
id="best-move-panel"
|
id="best-move-panel"
|
||||||
@@ -128,29 +205,20 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="rounded-lg bg-canvas-raised p-3 text-sm">
|
|
||||||
<p class="flex items-center justify-between gap-2 font-semibold">
|
|
||||||
<span>{turn_label(@status, @awaiting_reply)}</span>
|
|
||||||
<span class="text-xs font-normal text-muted">
|
|
||||||
You play {colour_name(@endgame.color)}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg bg-canvas-raised 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-muted">Loading tablebase…</p>
|
<p class="text-muted">Loading tablebase…</p>
|
||||||
<% @status == :blocked -> %>
|
<% @status == :blocked -> %>
|
||||||
<p class="font-semibold text-error">Tablebase unavailable</p>
|
<p class="font-semibold text-error-text">Tablebase unavailable</p>
|
||||||
<p class="text-error">{@blocked_reason}</p>
|
<p class="text-error-text">{@blocked_reason}</p>
|
||||||
<% @status == :solved -> %>
|
<% @status == :solved -> %>
|
||||||
<p class="font-semibold text-success-text">
|
<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-error">Failed</p>
|
<p class="font-semibold text-error-text">Failed</p>
|
||||||
<p class="text-error">
|
<p class="text-error-text">
|
||||||
{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."}
|
||||||
@@ -161,17 +229,17 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% @awaiting_reply -> %>
|
<% @awaiting_reply -> %>
|
||||||
<p class="text-muted">Opponent is replying…</p>
|
<p class="text-muted">Thinkin...</p>
|
||||||
<% @last_grade == :optimal -> %>
|
<% @last_grade == :optimal -> %>
|
||||||
<p class="font-semibold text-success-text">Optimal move</p>
|
<p class="font-semibold text-success-text">Optimal move</p>
|
||||||
<% @last_grade == :winning -> %>
|
<% @last_grade == :winning -> %>
|
||||||
<p class="font-semibold text-warning">
|
<p class="font-semibold text-warning-text">
|
||||||
{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-error">
|
<p class="font-semibold text-error-text">
|
||||||
{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"}
|
||||||
@@ -179,7 +247,8 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
<% @last_grade == :unknown -> %>
|
<% @last_grade == :unknown -> %>
|
||||||
<p class="font-semibold text-muted">Could not grade that move</p>
|
<p class="font-semibold text-muted">Could not grade that move</p>
|
||||||
<% true -> %>
|
<% true -> %>
|
||||||
<p class="text-muted">Make a move to have it graded.</p>
|
<p class="text-muted font-bold">Make a move.</p>
|
||||||
|
<p class="text-muted">You play {colour_name(@endgame.color)}</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<p :if={@status in [:solved, :failed]} class="mt-1 text-xs text-muted">
|
<p :if={@status in [:solved, :failed]} class="mt-1 text-xs text-muted">
|
||||||
Puzzle rating: {round(@endgame.rating)}
|
Puzzle rating: {round(@endgame.rating)}
|
||||||
@@ -188,6 +257,8 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
id="move-list"
|
id="move-list"
|
||||||
|
role="region"
|
||||||
|
aria-label="Moves"
|
||||||
class="flex-1 min-h-0 flex flex-col bg-canvas-raised rounded-lg p-3"
|
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) %>
|
||||||
@@ -243,14 +314,19 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
<p class={["text-xs font-semibold", class]}>{label}</p>
|
<p class={["text-xs font-semibold", class]}>{label}</p>
|
||||||
<table class="w-full text-left text-xs font-mono">
|
<table class="w-full text-left text-xs font-mono">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr
|
<tr :for={move <- moves}>
|
||||||
:for={move <- moves}
|
<td class={["py-0.5 pr-2", class]}>
|
||||||
phx-click="review_move"
|
<button
|
||||||
phx-value-uci={move.uci}
|
type="button"
|
||||||
class="cursor-pointer hover:bg-base-200"
|
phx-click="review_move"
|
||||||
title={"Play #{move.san}"}
|
phx-value-uci={move.uci}
|
||||||
>
|
class="text-left hover:underline"
|
||||||
<td class={["py-0.5 pr-2", class]}>{move.san}</td>
|
title={"Play #{move.san}"}
|
||||||
|
aria-label={"Play #{move.san}"}
|
||||||
|
>
|
||||||
|
{move.san}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
<td class="py-0.5 text-right text-muted" title="Distance to zeroing (DTZ)">
|
<td class="py-0.5 text-right text-muted" title="Distance to zeroing (DTZ)">
|
||||||
{dtz_text(move)}
|
{dtz_text(move)}
|
||||||
</td>
|
</td>
|
||||||
@@ -266,7 +342,7 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
[
|
[
|
||||||
{"Winning", "text-success-text", :win},
|
{"Winning", "text-success-text", :win},
|
||||||
{"Drawn", "text-muted", :draw},
|
{"Drawn", "text-muted", :draw},
|
||||||
{"Losing", "text-error", :loss},
|
{"Losing", "text-error-text", :loss},
|
||||||
{"Unknown", "text-muted", :unknown}
|
{"Unknown", "text-muted", :unknown}
|
||||||
]
|
]
|
||||||
|> Enum.flat_map(fn {label, class, outcome} ->
|
|> Enum.flat_map(fn {label, class, outcome} ->
|
||||||
@@ -308,9 +384,11 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
current_ply?(@ply, @review_index) && "underline"
|
current_ply?(@ply, @review_index) && "underline"
|
||||||
]}
|
]}
|
||||||
title={ply_title(@ply, @result)}
|
title={ply_title(@ply, @result)}
|
||||||
|
aria-current={current_ply?(@ply, @review_index) && "step"}
|
||||||
data-grade={@ply.grade}
|
data-grade={@ply.grade}
|
||||||
>
|
>
|
||||||
{@ply.san}
|
{@ply.san}
|
||||||
|
<span :if={ply_title(@ply, @result)} class="sr-only"> — {ply_title(@ply, @result)}</span>
|
||||||
</button>
|
</button>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span
|
<span
|
||||||
@@ -319,6 +397,7 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
data-grade={@ply.grade}
|
data-grade={@ply.grade}
|
||||||
>
|
>
|
||||||
{@ply.san}
|
{@ply.san}
|
||||||
|
<span :if={ply_title(@ply, @result)} class="sr-only"> — {ply_title(@ply, @result)}</span>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
"""
|
"""
|
||||||
@@ -335,13 +414,6 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
defp display_plies(true, line, _plies), do: line
|
defp display_plies(true, line, _plies), do: line
|
||||||
defp display_plies(false, _line, plies), do: plies
|
defp display_plies(false, _line, plies), do: plies
|
||||||
|
|
||||||
defp turn_label(:playing, false), do: "Your move"
|
|
||||||
defp turn_label(:playing, true), do: "Opponent's move"
|
|
||||||
defp turn_label(:solved, _awaiting_reply), do: "Solved"
|
|
||||||
defp turn_label(:failed, _awaiting_reply), do: "Finished"
|
|
||||||
defp turn_label(:blocked, _awaiting_reply), do: "Unavailable"
|
|
||||||
defp turn_label(_status, _awaiting_reply), do: "Loading…"
|
|
||||||
|
|
||||||
defp colour_name(:white), do: "White"
|
defp colour_name(:white), do: "White"
|
||||||
defp colour_name(:black), do: "Black"
|
defp colour_name(:black), do: "Black"
|
||||||
defp colour_name(colour), do: colour |> to_string() |> String.capitalize()
|
defp colour_name(colour), do: colour |> to_string() |> String.capitalize()
|
||||||
@@ -364,8 +436,8 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
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-success-text"
|
defp grade_class(:optimal), do: "text-success-text"
|
||||||
defp grade_class(:winning), do: "text-warning"
|
defp grade_class(:winning), do: "text-warning-text"
|
||||||
defp grade_class(:losing), do: "text-error"
|
defp grade_class(:losing), do: "text-error-text"
|
||||||
defp grade_class(_), do: "text-body"
|
defp grade_class(_), do: "text-body"
|
||||||
|
|
||||||
defp grade_label(nil, _result), do: nil
|
defp grade_label(nil, _result), do: nil
|
||||||
@@ -375,4 +447,128 @@ defmodule ChesstrainerWeb.PlayComponents do
|
|||||||
defp grade_label(:losing, :draw), do: "Loses the draw"
|
defp grade_label(:losing, :draw), do: "Loses the draw"
|
||||||
defp grade_label(:losing, _result), do: "Throws away the win"
|
defp grade_label(:losing, _result), do: "Throws away the win"
|
||||||
defp grade_label(:unknown, _result), do: "Not graded"
|
defp grade_label(:unknown, _result), do: "Not graded"
|
||||||
|
|
||||||
|
defp move_hint(:loading, _awaiting), do: "Loading the tablebase…"
|
||||||
|
|
||||||
|
defp move_hint(:blocked, _awaiting),
|
||||||
|
do: "The tablebase is unavailable, so moves cannot be entered."
|
||||||
|
|
||||||
|
defp move_hint(status, _awaiting) when status in [:solved, :failed],
|
||||||
|
do: "This puzzle is finished. Reset or try again."
|
||||||
|
|
||||||
|
defp move_hint(_status, true), do: "Waiting for the opponent's reply."
|
||||||
|
defp move_hint(_status, _awaiting), do: nil
|
||||||
|
|
||||||
|
# While the opponent's move is in flight the server's `fen` still points at
|
||||||
|
# the position before it, so describe the move the player just made instead.
|
||||||
|
defp position_fen(%{awaiting_reply: true, plies: plies}) do
|
||||||
|
case List.last(plies) do
|
||||||
|
%{fen_after: fen} -> fen
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp position_fen(%{fen: fen}) when is_binary(fen), do: fen
|
||||||
|
|
||||||
|
defp position_fen(%{endgame: %{fen: fen}}), do: fen
|
||||||
|
|
||||||
|
defp board_announcement(assigns) do
|
||||||
|
cond do
|
||||||
|
assigns.status == :loading ->
|
||||||
|
"Loading the tablebase."
|
||||||
|
|
||||||
|
assigns.status == :blocked ->
|
||||||
|
"Tablebase unavailable. #{assigns.blocked_reason || "Moves cannot be graded."}"
|
||||||
|
|
||||||
|
assigns.reviewing ->
|
||||||
|
review_announcement(assigns)
|
||||||
|
|
||||||
|
assigns.status == :solved ->
|
||||||
|
join_sentences([solved_sentence(assigns), check_sentence(assigns)])
|
||||||
|
|
||||||
|
assigns.status == :failed ->
|
||||||
|
join_sentences(["Failed.", failure_sentence(assigns), best_move_sentence(assigns)])
|
||||||
|
|
||||||
|
assigns.awaiting_reply ->
|
||||||
|
join_sentences([
|
||||||
|
"Move #{length(assigns.plies)}: you played #{last_san(assigns.plies)}.",
|
||||||
|
grade_sentence(assigns),
|
||||||
|
check_sentence(assigns),
|
||||||
|
"Waiting for the opponent's reply."
|
||||||
|
])
|
||||||
|
|
||||||
|
assigns.plies == [] ->
|
||||||
|
"You play #{colour_name(assigns.endgame.color)}. #{colour_name(assigns.endgame.color)} to move."
|
||||||
|
|
||||||
|
true ->
|
||||||
|
case List.last(assigns.plies) do
|
||||||
|
%{grade: nil} ->
|
||||||
|
join_sentences([
|
||||||
|
"Move #{length(assigns.plies)}: opponent played #{last_san(assigns.plies)}.",
|
||||||
|
check_sentence(assigns),
|
||||||
|
"Your move."
|
||||||
|
])
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
join_sentences([
|
||||||
|
"Move #{length(assigns.plies)}: you played #{last_san(assigns.plies)}.",
|
||||||
|
grade_sentence(assigns),
|
||||||
|
check_sentence(assigns),
|
||||||
|
"Your move."
|
||||||
|
])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp review_announcement(assigns) do
|
||||||
|
previous = Enum.at(assigns.line, assigns.review_index - 1)
|
||||||
|
|
||||||
|
position =
|
||||||
|
cond do
|
||||||
|
assigns.review_index <= 0 -> "Starting position."
|
||||||
|
previous -> "After #{previous.san}."
|
||||||
|
true -> "Final position."
|
||||||
|
end
|
||||||
|
|
||||||
|
"Reviewing position #{assigns.review_index} of #{length(assigns.line)}. #{position}"
|
||||||
|
end
|
||||||
|
|
||||||
|
defp failure_sentence(%{endgame: %{result: :draw}}), do: "That move loses the draw."
|
||||||
|
defp failure_sentence(_assigns), do: "That move throws away the win."
|
||||||
|
|
||||||
|
defp solved_sentence(%{endgame: %{result: :draw}}), do: "Draw held!"
|
||||||
|
defp solved_sentence(_assigns), do: "Solved!"
|
||||||
|
|
||||||
|
defp best_move_sentence(%{best_move: nil}), do: ""
|
||||||
|
defp best_move_sentence(%{best_move: best}), do: "Best was #{best}."
|
||||||
|
|
||||||
|
defp grade_sentence(%{plies: plies, endgame: endgame}) do
|
||||||
|
case List.last(plies) do
|
||||||
|
%{grade: grade} ->
|
||||||
|
case grade_label(grade, endgame.result) do
|
||||||
|
nil -> ""
|
||||||
|
label -> "#{label}."
|
||||||
|
end
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp check_sentence(%{last_checkmate: true}), do: "Checkmate."
|
||||||
|
defp check_sentence(%{last_check: true}), do: "Check."
|
||||||
|
defp check_sentence(_assigns), do: ""
|
||||||
|
|
||||||
|
defp last_san(plies) do
|
||||||
|
case List.last(plies) do
|
||||||
|
%{san: san} when is_binary(san) -> san
|
||||||
|
_ -> "a move"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp join_sentences(sentences) do
|
||||||
|
sentences
|
||||||
|
|> Enum.reject(&(&1 in [nil, ""]))
|
||||||
|
|> Enum.join(" ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,45 +3,31 @@ defmodule ChesstrainerWeb.MailingListController do
|
|||||||
|
|
||||||
alias Chesstrainer.MailingList
|
alias Chesstrainer.MailingList
|
||||||
alias Chesstrainer.MailingList.Notifier
|
alias Chesstrainer.MailingList.Notifier
|
||||||
|
alias ChesstrainerWeb.MailingListFormToken
|
||||||
|
|
||||||
@return_to "/#mailing-list"
|
@return_to "/#mailing-list"
|
||||||
@token_salt "mailing_list_confirm"
|
@token_salt "mailing_list_confirm"
|
||||||
@token_max_age 7 * 24 * 60 * 60
|
@token_max_age 7 * 24 * 60 * 60
|
||||||
|
|
||||||
def create(conn, %{"subscriber" => %{"email" => email}}) when is_binary(email) do
|
def create(conn, %{"subscriber" => params}) when is_map(params) do
|
||||||
email = String.trim(email)
|
email = params["email"]
|
||||||
|
|
||||||
case MailingList.subscribe(email) do
|
cond do
|
||||||
{:ok, :already_subscribed} ->
|
honeypot_filled?(params) ->
|
||||||
conn
|
fake_success(conn)
|
||||||
|> put_flash(:info, "You're already on the mailing list.")
|
|
||||||
|> redirect(to: @return_to)
|
|
||||||
|
|
||||||
{:ok, :confirmation_required} ->
|
not is_binary(email) ->
|
||||||
case send_confirmation(email) do
|
invalid_email(conn)
|
||||||
:ok ->
|
|
||||||
conn
|
|
||||||
|> put_flash(:info, "Check your inbox to confirm your subscription.")
|
|
||||||
|> redirect(to: @return_to)
|
|
||||||
|
|
||||||
:error ->
|
MailingListFormToken.verify(params["form_token"]) != :ok ->
|
||||||
conn
|
form_error(conn)
|
||||||
|> put_flash(:error, "We couldn't send the confirmation email. Please try again.")
|
|
||||||
|> redirect(to: @return_to)
|
|
||||||
end
|
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{}} ->
|
true ->
|
||||||
conn
|
subscribe(conn, email)
|
||||||
|> put_flash(:error, "Enter a valid email address.")
|
|
||||||
|> redirect(to: @return_to)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(conn, _params) do
|
def create(conn, _params), do: invalid_email(conn)
|
||||||
conn
|
|
||||||
|> put_flash(:error, "Enter a valid email address.")
|
|
||||||
|> redirect(to: @return_to)
|
|
||||||
end
|
|
||||||
|
|
||||||
def confirm(conn, %{"token" => token}) do
|
def confirm(conn, %{"token" => token}) do
|
||||||
case Phoenix.Token.verify(
|
case Phoenix.Token.verify(
|
||||||
@@ -77,13 +63,63 @@ defmodule ChesstrainerWeb.MailingListController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp send_confirmation(email) do
|
defp subscribe(conn, email) do
|
||||||
|
email = String.trim(email)
|
||||||
|
|
||||||
|
case MailingList.subscribe(email) do
|
||||||
|
{:ok, :already_subscribed} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "You're already on the mailing list.")
|
||||||
|
|> redirect(to: @return_to)
|
||||||
|
|
||||||
|
{:ok, :confirmation_required} ->
|
||||||
|
if MailingList.confirmation_allowed?(email) do
|
||||||
|
send_confirmation(conn, email)
|
||||||
|
else
|
||||||
|
fake_success(conn)
|
||||||
|
end
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{}} ->
|
||||||
|
invalid_email(conn)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp send_confirmation(conn, email) do
|
||||||
token = Phoenix.Token.sign(ChesstrainerWeb.Endpoint, @token_salt, email)
|
token = Phoenix.Token.sign(ChesstrainerWeb.Endpoint, @token_salt, email)
|
||||||
url = url(~p"/mailing-list/confirm/#{token}")
|
url = url(~p"/mailing-list/confirm/#{token}")
|
||||||
|
|
||||||
case Notifier.deliver_confirmation_instructions(email, url) do
|
case Notifier.deliver_confirmation_instructions(email, url) do
|
||||||
{:ok, _email} -> :ok
|
{:ok, _email} ->
|
||||||
{:error, _reason} -> :error
|
_ = MailingList.mark_confirmation_sent(email)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Check your inbox to confirm your subscription.")
|
||||||
|
|> redirect(to: @return_to)
|
||||||
|
|
||||||
|
{:error, _reason} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "We couldn't send the confirmation email. Please try again.")
|
||||||
|
|> redirect(to: @return_to)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp honeypot_filled?(params), do: params["company"] not in [nil, ""]
|
||||||
|
|
||||||
|
defp fake_success(conn) do
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Check your inbox to confirm your subscription.")
|
||||||
|
|> redirect(to: @return_to)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp form_error(conn) do
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Please refresh the page and try again.")
|
||||||
|
|> redirect(to: @return_to)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp invalid_email(conn) do
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Enter a valid email address.")
|
||||||
|
|> redirect(to: @return_to)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
<Layouts.flash_group flash={@flash} />
|
<Layouts.flash_group flash={@flash} />
|
||||||
<main>
|
<main id="main-content" tabindex="-1">
|
||||||
<section class="hero">
|
<section class="hero">
|
||||||
<div class="hero-copy">
|
<div class="hero-copy">
|
||||||
<div class="eyebrow">
|
<div class="eyebrow">
|
||||||
<.icon_spark /> Endgames, made clear
|
<.icon_spark /> Endgames, simplified
|
||||||
</div>
|
</div>
|
||||||
<h1>
|
<h1>
|
||||||
Learn to see the <em>winning move.</em>
|
Master the <em>endgame.</em>
|
||||||
</h1>
|
</h1>
|
||||||
<p>
|
<p>
|
||||||
Short, focused endgame sessions that build the instincts you need
|
Train your intuition to find the winning moves under pressure. Puzzle sessions focused purely on technical execution.
|
||||||
when every move matters.
|
|
||||||
</p>
|
</p>
|
||||||
<div class="hero-actions">
|
<div class="hero-actions">
|
||||||
<.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
|
<.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
|
||||||
@@ -35,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="learning-strip" id="method">
|
<%!-- <section class="learning-strip" id="method">
|
||||||
<p>Built for the part of chess that decides everything.</p>
|
<p>Built for the part of chess that decides everything.</p>
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
<strong>{count_label(@puzzle_count)}</strong>
|
<strong>{count_label(@puzzle_count)}</strong>
|
||||||
@@ -45,19 +44,19 @@
|
|||||||
<strong>{@user_count}</strong>
|
<strong>{@user_count}</strong>
|
||||||
<span>Players improving their endgame</span>
|
<span>Players improving their endgame</span>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section> --%>
|
||||||
|
|
||||||
<section class="puzzle-section" id="puzzles">
|
<%!-- <section class="puzzle-section" id="puzzles">
|
||||||
<div class="section-heading">
|
<div class="section-heading">
|
||||||
<div>
|
<div>
|
||||||
<span class="section-kicker">Choose your challenge</span>
|
<span class="section-kicker">Choose your lesson</span>
|
||||||
<h2>
|
<h2>
|
||||||
One position. <br /> One clear idea.
|
One position. <br /> One idea.
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
No noise, no endless variations. Each exercise teaches a pattern
|
Each exercise teaches a pattern
|
||||||
you’ll recognize over the board.
|
that you’ll recognise over the board.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="puzzle-grid">
|
<div class="puzzle-grid">
|
||||||
@@ -69,7 +68,7 @@
|
|||||||
/>
|
/>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section> --%>
|
||||||
|
|
||||||
<.mailing_list_signup />
|
<.mailing_list_signup />
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ defmodule ChesstrainerWeb.EndgameLive.GuestTrain do
|
|||||||
:if={@endgame}
|
:if={@endgame}
|
||||||
session={is_nil(@limit_reached)}
|
session={is_nil(@limit_reached)}
|
||||||
endgame={@endgame}
|
endgame={@endgame}
|
||||||
|
fen={@fen}
|
||||||
status={@status}
|
status={@status}
|
||||||
blocked_reason={@blocked_reason}
|
blocked_reason={@blocked_reason}
|
||||||
best_move={@best_move}
|
best_move={@best_move}
|
||||||
@@ -84,6 +85,10 @@ defmodule ChesstrainerWeb.EndgameLive.GuestTrain do
|
|||||||
awaiting_reply={@awaiting_reply}
|
awaiting_reply={@awaiting_reply}
|
||||||
last_grade={@last_grade}
|
last_grade={@last_grade}
|
||||||
awaiting_best_line={@awaiting_best_line}
|
awaiting_best_line={@awaiting_best_line}
|
||||||
|
move_input={@move_input}
|
||||||
|
move_input_error={@move_input_error}
|
||||||
|
last_check={@last_check}
|
||||||
|
last_checkmate={@last_checkmate}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p :if={@loading} class="text-base-content/70">Picking a random puzzle…</p>
|
<p :if={@loading} class="text-base-content/70">Picking a random puzzle…</p>
|
||||||
@@ -150,6 +155,13 @@ defmodule ChesstrainerWeb.EndgameLive.GuestTrain do
|
|||||||
def handle_event("endgame_move_played", params, socket),
|
def handle_event("endgame_move_played", params, socket),
|
||||||
do: PlayCore.move_played(socket, params)
|
do: PlayCore.move_played(socket, params)
|
||||||
|
|
||||||
|
def handle_event("submit_move", params, socket), do: PlayCore.submit_move(socket, params)
|
||||||
|
|
||||||
|
def handle_event("move_input", params, socket), do: PlayCore.move_input_changed(socket, params)
|
||||||
|
|
||||||
|
def handle_event("move_input_error", params, socket),
|
||||||
|
do: PlayCore.move_input_error(socket, params)
|
||||||
|
|
||||||
def handle_event("opponent_reply_applied", params, socket),
|
def handle_event("opponent_reply_applied", params, socket),
|
||||||
do: PlayCore.opponent_reply_applied(socket, params)
|
do: PlayCore.opponent_reply_applied(socket, params)
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ defmodule ChesstrainerWeb.EndgameLive.Index do
|
|||||||
type="button"
|
type="button"
|
||||||
id="clear-endgame-search"
|
id="clear-endgame-search"
|
||||||
phx-click="clear_search"
|
phx-click="clear_search"
|
||||||
class="text-sm text-primary underline underline-offset-4 hover:text-primary/80"
|
class="text-sm text-primary-text underline underline-offset-4 hover:text-primary-text/80"
|
||||||
>
|
>
|
||||||
Clear
|
Clear
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -23,10 +23,12 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
<span>FEN: {@endgame.fen}</span>
|
<span>FEN: {@endgame.fen}</span>
|
||||||
<button
|
<button
|
||||||
id="copy-fen-btn"
|
id="copy-fen-btn"
|
||||||
|
type="button"
|
||||||
phx-hook="CopyFen"
|
phx-hook="CopyFen"
|
||||||
data-fen={@endgame.fen}
|
data-fen={@endgame.fen}
|
||||||
class="inline-flex items-center cursor-pointer"
|
class="inline-flex items-center justify-center rounded p-1.5 cursor-pointer"
|
||||||
title="Copy FEN to clipboard"
|
title="Copy FEN to clipboard"
|
||||||
|
aria-label="Copy FEN to clipboard"
|
||||||
>
|
>
|
||||||
<.icon name="hero-document-duplicate" class="w-3.5 h-3.5" />
|
<.icon name="hero-document-duplicate" class="w-3.5 h-3.5" />
|
||||||
</button>
|
</button>
|
||||||
@@ -44,6 +46,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
|
|
||||||
<PlayComponents.play_surface
|
<PlayComponents.play_surface
|
||||||
endgame={@endgame}
|
endgame={@endgame}
|
||||||
|
fen={@fen}
|
||||||
status={@status}
|
status={@status}
|
||||||
blocked_reason={@blocked_reason}
|
blocked_reason={@blocked_reason}
|
||||||
best_move={@best_move}
|
best_move={@best_move}
|
||||||
@@ -56,6 +59,10 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
awaiting_reply={@awaiting_reply}
|
awaiting_reply={@awaiting_reply}
|
||||||
last_grade={@last_grade}
|
last_grade={@last_grade}
|
||||||
awaiting_best_line={@awaiting_best_line}
|
awaiting_best_line={@awaiting_best_line}
|
||||||
|
move_input={@move_input}
|
||||||
|
move_input_error={@move_input_error}
|
||||||
|
last_check={@last_check}
|
||||||
|
last_checkmate={@last_checkmate}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div :if={@user_rating} class="mb-4">
|
<div :if={@user_rating} class="mb-4">
|
||||||
@@ -76,6 +83,13 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
def handle_event("endgame_move_played", params, socket),
|
def handle_event("endgame_move_played", params, socket),
|
||||||
do: PlayCore.move_played(socket, params)
|
do: PlayCore.move_played(socket, params)
|
||||||
|
|
||||||
|
def handle_event("submit_move", params, socket), do: PlayCore.submit_move(socket, params)
|
||||||
|
|
||||||
|
def handle_event("move_input", params, socket), do: PlayCore.move_input_changed(socket, params)
|
||||||
|
|
||||||
|
def handle_event("move_input_error", params, socket),
|
||||||
|
do: PlayCore.move_input_error(socket, params)
|
||||||
|
|
||||||
def handle_event("opponent_reply_applied", params, socket),
|
def handle_event("opponent_reply_applied", params, socket),
|
||||||
do: PlayCore.opponent_reply_applied(socket, params)
|
do: PlayCore.opponent_reply_applied(socket, params)
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
alias Chesstrainer.Endgames.Tablebase
|
alias Chesstrainer.Endgames.Tablebase
|
||||||
alias Chesstrainer.Ratings
|
alias Chesstrainer.Ratings
|
||||||
|
|
||||||
|
@uci_pattern ~r/^[a-h][1-8][a-h][1-8][qrbn]?$/
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Loads `endgame` and starts an attempt on it.
|
Loads `endgame` and starts an attempt on it.
|
||||||
|
|
||||||
@@ -53,6 +55,10 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
|> assign(:last_grade, nil)
|
|> assign(:last_grade, nil)
|
||||||
|> assign(:awaiting_reply, false)
|
|> assign(:awaiting_reply, false)
|
||||||
|> assign(:last_rating_delta, nil)
|
|> assign(:last_rating_delta, nil)
|
||||||
|
|> assign(:last_check, false)
|
||||||
|
|> assign(:last_checkmate, false)
|
||||||
|
|> assign(:move_input, "")
|
||||||
|
|> assign(:move_input_error, nil)
|
||||||
|> load_attempt()
|
|> load_attempt()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -60,6 +66,8 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
%{"from" => from, "to" => to, "san" => san} = params
|
%{"from" => from, "to" => to, "san" => san} = params
|
||||||
promotion = params["promotion"]
|
promotion = params["promotion"]
|
||||||
draw = params["draw"] || false
|
draw = params["draw"] || false
|
||||||
|
check = params["check"] || false
|
||||||
|
checkmate = params["checkmate"] || false
|
||||||
prev_fen = params["prev_fen"] || socket.assigns.fen
|
prev_fen = params["prev_fen"] || socket.assigns.fen
|
||||||
fen_after = params["fen"] || socket.assigns.fen
|
fen_after = params["fen"] || socket.assigns.fen
|
||||||
|
|
||||||
@@ -76,16 +84,72 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
put_flash(socket, :error, "That move is out of sequence. Press Reset to try again.")}
|
put_flash(socket, :error, "That move is out of sequence. Press Reset to try again.")}
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
grade_and_record(socket, from, to, promotion, san, fen_after, draw)
|
grade_and_record(socket, from, to, promotion, san, fen_after, draw, check, checkmate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Plays the move typed into the keyboard move input.
|
||||||
|
|
||||||
|
The tablebase already knows every legal move in the position, so matching SAN
|
||||||
|
or UCI against it validates the input without a chess engine on the server.
|
||||||
|
The board hook applies the move and reports it through the normal move events.
|
||||||
|
"""
|
||||||
|
def submit_move(socket, %{"move" => input}) do
|
||||||
|
cond do
|
||||||
|
socket.assigns.reviewing ->
|
||||||
|
move_input_rejected(socket, "Leave review to make a move.")
|
||||||
|
|
||||||
|
socket.assigns.status != :playing ->
|
||||||
|
move_input_rejected(socket, "This puzzle is not open for moves right now.")
|
||||||
|
|
||||||
|
socket.assigns.awaiting_reply ->
|
||||||
|
move_input_rejected(socket, "Wait for the opponent's reply.")
|
||||||
|
|
||||||
|
true ->
|
||||||
|
case parse_move_input(socket.assigns.tablebase, input) do
|
||||||
|
%Tablebase.Move{} = move ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(:move_input, "")
|
||||||
|
|> assign(:move_input_error, nil)
|
||||||
|
|> push_event("apply_move", reply_payload(move))}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
move_input_rejected(
|
||||||
|
socket,
|
||||||
|
"Not a legal move here. Try SAN like Nf3, or squares like g1f3."
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def submit_move(socket, _params), do: {:noreply, socket}
|
||||||
|
|
||||||
|
def move_input_changed(socket, %{"move" => value}) when is_binary(value) do
|
||||||
|
{:noreply, socket |> assign(:move_input, value) |> assign(:move_input_error, nil)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def move_input_changed(socket, _params), do: {:noreply, socket}
|
||||||
|
|
||||||
|
def move_input_error(socket, %{"message" => message}) when is_binary(message) do
|
||||||
|
{:noreply, assign(socket, :move_input_error, message)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def move_input_error(socket, _params), do: {:noreply, socket}
|
||||||
|
|
||||||
def opponent_reply_applied(socket, params) do
|
def opponent_reply_applied(socket, params) do
|
||||||
%{"fen" => fen} = params
|
%{"fen" => fen} = params
|
||||||
draw = params["draw"] || false
|
draw = params["draw"] || false
|
||||||
|
check = params["check"] || false
|
||||||
|
checkmate = params["checkmate"] || false
|
||||||
|
|
||||||
if socket.assigns.awaiting_reply do
|
if socket.assigns.awaiting_reply do
|
||||||
socket = record_opponent_ply(socket, fen, params["san"])
|
socket =
|
||||||
|
socket
|
||||||
|
|> record_opponent_ply(fen, params["san"])
|
||||||
|
|> assign(:last_check, check)
|
||||||
|
|> assign(:last_checkmate, checkmate)
|
||||||
|
|
||||||
if draw and socket.assigns.endgame.result == :draw do
|
if draw and socket.assigns.endgame.result == :draw do
|
||||||
solve_attempt(socket)
|
solve_attempt(socket)
|
||||||
@@ -100,6 +164,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
|> assign(:awaiting_reply, false)
|
|> assign(:awaiting_reply, false)
|
||||||
|> assign(:status, :playing)
|
|> assign(:status, :playing)
|
||||||
|> assign(:blocked_reason, nil)
|
|> assign(:blocked_reason, nil)
|
||||||
|
|> assign(:move_input_error, nil)
|
||||||
|> push_event("resume_board", %{})}
|
|> push_event("resume_board", %{})}
|
||||||
|
|
||||||
other ->
|
other ->
|
||||||
@@ -141,6 +206,10 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
|> assign(:last_from_to, "None yet")
|
|> assign(:last_from_to, "None yet")
|
||||||
|> assign(:last_grade, nil)
|
|> assign(:last_grade, nil)
|
||||||
|> assign(:last_rating_delta, nil)
|
|> assign(:last_rating_delta, nil)
|
||||||
|
|> assign(:last_check, false)
|
||||||
|
|> assign(:last_checkmate, false)
|
||||||
|
|> assign(:move_input, "")
|
||||||
|
|> assign(:move_input_error, nil)
|
||||||
|
|
||||||
{:noreply, load_attempt(socket)}
|
{:noreply, load_attempt(socket)}
|
||||||
end
|
end
|
||||||
@@ -334,7 +403,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
"The tablebase is unavailable (#{inspect(reason)})."
|
"The tablebase is unavailable (#{inspect(reason)})."
|
||||||
end
|
end
|
||||||
|
|
||||||
defp grade_and_record(socket, from, to, promotion, san, fen_after, draw) do
|
defp grade_and_record(socket, from, to, promotion, san, fen_after, draw, check, checkmate) do
|
||||||
case find_move(socket.assigns.tablebase, from, to, promotion) do
|
case find_move(socket.assigns.tablebase, from, to, promotion) do
|
||||||
nil ->
|
nil ->
|
||||||
{:noreply, put_flash(socket, :error, "Could not identify that move in the tablebase.")}
|
{:noreply, put_flash(socket, :error, "Could not identify that move in the tablebase.")}
|
||||||
@@ -354,6 +423,10 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
|> assign(:last_from_to, "#{from} ➔ #{to}")
|
|> assign(:last_from_to, "#{from} ➔ #{to}")
|
||||||
|> assign(:last_san, san)
|
|> assign(:last_san, san)
|
||||||
|> assign(:last_grade, grade)
|
|> assign(:last_grade, grade)
|
||||||
|
|> assign(:last_check, check)
|
||||||
|
|> assign(:last_checkmate, checkmate)
|
||||||
|
|> assign(:move_input, "")
|
||||||
|
|> assign(:move_input_error, nil)
|
||||||
|> assign(:plies, socket.assigns.plies ++ [ply])
|
|> assign(:plies, socket.assigns.plies ++ [ply])
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
@@ -450,7 +523,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
|> assign(:last_rating_delta, nil)
|
|> assign(:last_rating_delta, nil)
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:info,
|
:info,
|
||||||
"Replay recorded. Your rating is unchanged because you played this recently."
|
"Your rating is unchanged because you played this puzzle recently."
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -525,6 +598,38 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
|||||||
|
|
||||||
defp find_move_by_uci(_tablebase, _uci), do: nil
|
defp find_move_by_uci(_tablebase, _uci), do: nil
|
||||||
|
|
||||||
|
defp parse_move_input(%Tablebase{} = tablebase, input) when is_binary(input) do
|
||||||
|
normalized = input |> String.trim() |> String.downcase() |> String.replace(" ", "")
|
||||||
|
uci = String.replace(normalized, "-", "")
|
||||||
|
|
||||||
|
cond do
|
||||||
|
normalized == "" -> nil
|
||||||
|
Regex.match?(@uci_pattern, uci) -> find_move_by_uci(tablebase, uci)
|
||||||
|
true -> find_move_by_san(tablebase, normalize_san(normalized))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_move_input(_tablebase, _input), do: nil
|
||||||
|
|
||||||
|
defp find_move_by_san(%Tablebase{moves: moves}, san) when is_list(moves) and is_binary(san) do
|
||||||
|
Enum.find(moves, &(normalize_san(&1.san) == san))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp find_move_by_san(_tablebase, _san), do: nil
|
||||||
|
|
||||||
|
defp normalize_san(san) when is_binary(san) do
|
||||||
|
san
|
||||||
|
|> String.downcase()
|
||||||
|
|> String.replace("=", "")
|
||||||
|
|> String.replace(~r/[+#!?]/, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp normalize_san(_san), do: nil
|
||||||
|
|
||||||
|
defp move_input_rejected(socket, message) do
|
||||||
|
{:noreply, assign(socket, :move_input_error, message)}
|
||||||
|
end
|
||||||
|
|
||||||
# Compare only the board and side to move: chess.js may normalise the rest
|
# Compare only the board and side to move: chess.js may normalise the rest
|
||||||
# (castling/en-passant/halfmove/fullmove) differently from the stored FEN.
|
# (castling/en-passant/halfmove/fullmove) differently from the stored FEN.
|
||||||
defp same_position?(fen_a, fen_b), do: position_key(fen_a) == position_key(fen_b)
|
defp same_position?(fen_a, fen_b), do: position_key(fen_a) == position_key(fen_b)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ defmodule ChesstrainerWeb.EndgameLive.Show do
|
|||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<.board game={@game} myself="board" />
|
<.board game={@game} myself="board" interactive={false} />
|
||||||
|
|
||||||
<.list>
|
<.list>
|
||||||
<:item title="Fen">{@endgame.fen}</:item>
|
<:item title="Fen">{@endgame.fen}</:item>
|
||||||
@@ -54,8 +54,9 @@ defmodule ChesstrainerWeb.EndgameLive.Show do
|
|||||||
type="button"
|
type="button"
|
||||||
phx-hook=".CopyPublicCode"
|
phx-hook=".CopyPublicCode"
|
||||||
data-code={@endgame.public_code}
|
data-code={@endgame.public_code}
|
||||||
class="ml-2 inline-flex cursor-pointer items-center"
|
class="ml-2 inline-flex cursor-pointer items-center justify-center rounded p-1.5"
|
||||||
title="Copy public code"
|
title="Copy public code"
|
||||||
|
aria-label="Copy public code to clipboard"
|
||||||
>
|
>
|
||||||
<.icon name="hero-document-duplicate" class="w-3.5 h-3.5" />
|
<.icon name="hero-document-duplicate" class="w-3.5 h-3.5" />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
|||||||
<PlayComponents.play_surface
|
<PlayComponents.play_surface
|
||||||
session={true}
|
session={true}
|
||||||
endgame={@endgame}
|
endgame={@endgame}
|
||||||
|
fen={@fen}
|
||||||
status={@status}
|
status={@status}
|
||||||
blocked_reason={@blocked_reason}
|
blocked_reason={@blocked_reason}
|
||||||
best_move={@best_move}
|
best_move={@best_move}
|
||||||
@@ -94,6 +95,10 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
|||||||
awaiting_reply={@awaiting_reply}
|
awaiting_reply={@awaiting_reply}
|
||||||
last_grade={@last_grade}
|
last_grade={@last_grade}
|
||||||
awaiting_best_line={@awaiting_best_line}
|
awaiting_best_line={@awaiting_best_line}
|
||||||
|
move_input={@move_input}
|
||||||
|
move_input_error={@move_input_error}
|
||||||
|
last_check={@last_check}
|
||||||
|
last_checkmate={@last_checkmate}
|
||||||
/>
|
/>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
||||||
@@ -164,7 +169,7 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<.button navigate={~p"/"} variant="ghost" class="mt-2 w-full justify-center">
|
<.button navigate={~p"/"} variant="ghost" class="mt-2 w-full justify-center">
|
||||||
Cancel
|
<.icon name="hero-arrow-left" />Return Home
|
||||||
</.button>
|
</.button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -255,6 +260,13 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
|||||||
{:noreply, account_completion(socket)}
|
{:noreply, account_completion(socket)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("submit_move", params, socket), do: PlayCore.submit_move(socket, params)
|
||||||
|
|
||||||
|
def handle_event("move_input", params, socket), do: PlayCore.move_input_changed(socket, params)
|
||||||
|
|
||||||
|
def handle_event("move_input_error", params, socket),
|
||||||
|
do: PlayCore.move_input_error(socket, params)
|
||||||
|
|
||||||
def handle_event("opponent_reply_applied", params, socket) do
|
def handle_event("opponent_reply_applied", params, socket) do
|
||||||
{:noreply, socket} = PlayCore.opponent_reply_applied(socket, params)
|
{:noreply, socket} = PlayCore.opponent_reply_applied(socket, params)
|
||||||
{:noreply, account_completion(socket)}
|
{:noreply, account_completion(socket)}
|
||||||
@@ -374,6 +386,6 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp gain_class(delta) when is_number(delta) and delta > 0, do: "text-success-text"
|
defp gain_class(delta) when is_number(delta) and delta > 0, do: "text-success-text"
|
||||||
defp gain_class(delta) when is_number(delta) and delta < 0, do: "text-error"
|
defp gain_class(delta) when is_number(delta) and delta < 0, do: "text-error-text"
|
||||||
defp gain_class(_delta), do: "text-muted"
|
defp gain_class(_delta), do: "text-muted"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,20 +7,18 @@ defmodule ChesstrainerWeb.UserLive.Login do
|
|||||||
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
||||||
<div class="mx-auto max-w-sm space-y-4">
|
<div class="mx-auto max-w-sm space-y-4">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<.header>
|
<h1 class="settings-header">Log in</h1>
|
||||||
<p>Log in</p>
|
<%= if @current_scope do %>
|
||||||
<:subtitle>
|
You need to reauthenticate to perform sensitive actions on your account.
|
||||||
<%= if @current_scope do %>
|
<% else %>
|
||||||
You need to reauthenticate to perform sensitive actions on your account.
|
<p class="settings-subtitle my-4">
|
||||||
<% 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-primary-text 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.
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</:subtitle>
|
|
||||||
</.header>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.form
|
<.form
|
||||||
@@ -58,7 +56,7 @@ defmodule ChesstrainerWeb.UserLive.Login do
|
|||||||
<p class="text-center text-sm">
|
<p class="text-center text-sm">
|
||||||
<.link
|
<.link
|
||||||
navigate={~p"/users/reset-password"}
|
navigate={~p"/users/reset-password"}
|
||||||
class="font-semibold text-primary hover:underline"
|
class="font-semibold text-primary-text hover:underline"
|
||||||
>
|
>
|
||||||
Forgot your password?
|
Forgot your password?
|
||||||
</.link>
|
</.link>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ defmodule ChesstrainerWeb.UserLive.Profile do
|
|||||||
alias Chesstrainer.Accounts
|
alias Chesstrainer.Accounts
|
||||||
alias Chesstrainer.Accounts.Scope
|
alias Chesstrainer.Accounts.Scope
|
||||||
alias Chesstrainer.Attempts
|
alias Chesstrainer.Attempts
|
||||||
|
alias Chesstrainer.MailingList
|
||||||
|
|
||||||
@recent_attempts 25
|
@recent_attempts 25
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ defmodule ChesstrainerWeb.UserLive.Profile do
|
|||||||
class={[
|
class={[
|
||||||
"border-b-2 -mb-px px-3 py-2 text-sm font-semibold",
|
"border-b-2 -mb-px px-3 py-2 text-sm font-semibold",
|
||||||
if(@live_action == tab.id,
|
if(@live_action == tab.id,
|
||||||
do: "border-primary text-primary",
|
do: "border-primary text-primary-text",
|
||||||
else: "border-transparent text-base-content/60 hover:text-base-content"
|
else: "border-transparent text-base-content/60 hover:text-base-content"
|
||||||
)
|
)
|
||||||
]}
|
]}
|
||||||
@@ -159,6 +160,27 @@ defmodule ChesstrainerWeb.UserLive.Profile do
|
|||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="mailing-list-settings" class="space-y-3 rounded-lg border border-base-300 p-4">
|
||||||
|
<h2 class="settings-header">Mailing list</h2>
|
||||||
|
|
||||||
|
<p :if={@mailing_list_subscribed?} class="settings-subtitle">
|
||||||
|
You're subscribed to occasional endgame tips and site news.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p :if={!@mailing_list_subscribed?} class="settings-subtitle">
|
||||||
|
You're not subscribed to the mailing list.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<.button
|
||||||
|
:if={@mailing_list_subscribed?}
|
||||||
|
id="unsubscribe-mailing-list"
|
||||||
|
variant="secondary"
|
||||||
|
phx-click="unsubscribe_mailing_list"
|
||||||
|
>
|
||||||
|
Unsubscribe
|
||||||
|
</.button>
|
||||||
|
</section>
|
||||||
|
|
||||||
<p id="settings-empty-state" class="text-sm text-base-content/60">
|
<p id="settings-empty-state" class="text-sm text-base-content/60">
|
||||||
More site settings will appear here as they become available.
|
More site settings will appear here as they become available.
|
||||||
</p>
|
</p>
|
||||||
@@ -332,6 +354,24 @@ defmodule ChesstrainerWeb.UserLive.Profile do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("unsubscribe_mailing_list", _params, socket) do
|
||||||
|
user = socket.assigns.current_scope.user
|
||||||
|
|
||||||
|
case MailingList.unsubscribe_user(user) do
|
||||||
|
{:ok, _subscriber} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(:mailing_list_subscribed?, false)
|
||||||
|
|> put_flash(:info, "You've been removed from the mailing list.")}
|
||||||
|
|
||||||
|
{:error, :not_found} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(:mailing_list_subscribed?, false)
|
||||||
|
|> put_flash(:info, "You're not on the mailing list.")}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_event("delete_account", _params, socket) do
|
def handle_event("delete_account", _params, socket) do
|
||||||
user = socket.assigns.current_scope.user
|
user = socket.assigns.current_scope.user
|
||||||
true = Accounts.sudo_mode?(user)
|
true = Accounts.sudo_mode?(user)
|
||||||
@@ -348,10 +388,16 @@ defmodule ChesstrainerWeb.UserLive.Profile do
|
|||||||
case socket.assigns.live_action do
|
case socket.assigns.live_action do
|
||||||
:account -> assign_account(socket)
|
:account -> assign_account(socket)
|
||||||
:data -> assign_data(socket)
|
:data -> assign_data(socket)
|
||||||
|
:settings -> assign_settings(socket)
|
||||||
_ -> socket
|
_ -> socket
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp assign_settings(socket) do
|
||||||
|
user = socket.assigns.current_scope.user
|
||||||
|
assign(socket, :mailing_list_subscribed?, MailingList.user_subscribed?(user))
|
||||||
|
end
|
||||||
|
|
||||||
defp assign_account(socket) do
|
defp assign_account(socket) do
|
||||||
user = socket.assigns.current_scope.user
|
user = socket.assigns.current_scope.user
|
||||||
email_changeset = Accounts.change_user_email(user, %{}, validate_unique: false)
|
email_changeset = Accounts.change_user_email(user, %{}, validate_unique: false)
|
||||||
|
|||||||
@@ -11,16 +11,17 @@ defmodule ChesstrainerWeb.UserLive.Registration do
|
|||||||
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
||||||
<div class="mx-auto max-w-sm">
|
<div class="mx-auto max-w-sm">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<.header>
|
<h1 class="settings-header">Register for an account</h1>
|
||||||
Register for an account
|
<p class="settings-subtitle my-4">
|
||||||
<:subtitle>
|
Already registered?
|
||||||
Already registered?
|
<.link
|
||||||
<.link navigate={~p"/users/log-in"} class="font-semibold text-primary hover:underline">
|
navigate={~p"/users/log-in"}
|
||||||
Log in
|
class="font-semibold text-primary-text hover:underline"
|
||||||
</.link>
|
>
|
||||||
to your account now.
|
Log in
|
||||||
</:subtitle>
|
</.link>
|
||||||
</.header>
|
to your account now
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.form for={@form} id="registration_form" phx-submit="save" phx-change="validate">
|
<.form for={@form} id="registration_form" phx-submit="save" phx-change="validate">
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ defmodule ChesstrainerWeb.UserLive.ResetPassword do
|
|||||||
<p class="text-center text-sm">
|
<p class="text-center text-sm">
|
||||||
<.link
|
<.link
|
||||||
navigate={~p"/users/log-in"}
|
navigate={~p"/users/log-in"}
|
||||||
class="font-semibold text-primary hover:underline"
|
class="font-semibold text-primary-text hover:underline"
|
||||||
>
|
>
|
||||||
Back to log in
|
Back to log in
|
||||||
</.link>
|
</.link>
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
defmodule ChesstrainerWeb.MailingListFormToken do
|
||||||
|
@moduledoc """
|
||||||
|
Signed timestamp hidden in the mailing-list signup form.
|
||||||
|
|
||||||
|
Used as a timing check: submissions that arrive faster than a human could
|
||||||
|
plausibly fill the form are rejected. The timestamp is signed so a bot
|
||||||
|
cannot simply make one up.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@salt "mailing_list_form"
|
||||||
|
@max_age 2 * 60 * 60
|
||||||
|
@min_seconds 2
|
||||||
|
|
||||||
|
@type verify_result :: :ok | :too_fast | :expired | :invalid
|
||||||
|
|
||||||
|
@doc "Signs the current time for the hidden form field."
|
||||||
|
def sign, do: sign(System.system_time(:second))
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def sign(signed_at) when is_integer(signed_at) do
|
||||||
|
Phoenix.Token.sign(ChesstrainerWeb.Endpoint, @salt, signed_at, signed_at: signed_at)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "Checks a submitted form token."
|
||||||
|
@spec verify(term()) :: verify_result()
|
||||||
|
def verify(token) when is_binary(token) do
|
||||||
|
now = System.system_time(:second)
|
||||||
|
|
||||||
|
case Phoenix.Token.verify(ChesstrainerWeb.Endpoint, @salt, token, max_age: @max_age) do
|
||||||
|
{:ok, signed_at} when is_integer(signed_at) and now - signed_at >= @min_seconds -> :ok
|
||||||
|
{:ok, _signed_at} -> :too_fast
|
||||||
|
{:error, :expired} -> :expired
|
||||||
|
{:error, _reason} -> :invalid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def verify(_token), do: :invalid
|
||||||
|
end
|
||||||
@@ -62,6 +62,7 @@ defmodule Chesstrainer.MixProject do
|
|||||||
depth: 1},
|
depth: 1},
|
||||||
{:swoosh, "~> 1.16"},
|
{:swoosh, "~> 1.16"},
|
||||||
{:req, "~> 0.5"},
|
{:req, "~> 0.5"},
|
||||||
|
{:gen_smtp, "~> 1.2"},
|
||||||
{:telemetry_metrics, "~> 1.0"},
|
{:telemetry_metrics, "~> 1.0"},
|
||||||
{:telemetry_poller, "~> 1.0"},
|
{:telemetry_poller, "~> 1.0"},
|
||||||
{:gettext, "~> 1.0"},
|
{:gettext, "~> 1.0"},
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"},
|
"file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"},
|
||||||
"finch": {:hex, :finch, "0.23.0", "e3f9287ac25a8832f848b144c2b57346aac65b205e2e0629a52adfe6507fd837", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "80e58d3f936f57e3fdf404f83a3642897ae6d9fb642934e46da4d8fe761b99d5"},
|
"finch": {:hex, :finch, "0.23.0", "e3f9287ac25a8832f848b144c2b57346aac65b205e2e0629a52adfe6507fd837", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "80e58d3f936f57e3fdf404f83a3642897ae6d9fb642934e46da4d8fe761b99d5"},
|
||||||
"fine": {:hex, :fine, "0.1.6", "4bf7151493443c454aac9f2fa2f34f5fefd0346a83fb5586a016c4a135c63247", [:mix], [], "hexpm", "5638eb4495488e885ebec167fa57973e5c35e1a50c344eb7666c90ec1c4e3b12"},
|
"fine": {:hex, :fine, "0.1.6", "4bf7151493443c454aac9f2fa2f34f5fefd0346a83fb5586a016c4a135c63247", [:mix], [], "hexpm", "5638eb4495488e885ebec167fa57973e5c35e1a50c344eb7666c90ec1c4e3b12"},
|
||||||
|
"gen_smtp": {:hex, :gen_smtp, "1.3.0", "62c3d91f0dcf6ce9db71bcb6881d7ad0d1d834c7f38c13fa8e952f4104a8442e", [:rebar3], [{:ranch, ">= 1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "0b73fbf069864ecbce02fe653b16d3f35fd889d0fdd4e14527675565c39d84e6"},
|
||||||
"gettext": {:hex, :gettext, "1.0.2", "5457e1fd3f4abe47b0e13ff85086aabae760497a3497909b8473e0acee57673b", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "eab805501886802071ad290714515c8c4a17196ea76e5afc9d06ca85fb1bfeb3"},
|
"gettext": {:hex, :gettext, "1.0.2", "5457e1fd3f4abe47b0e13ff85086aabae760497a3497909b8473e0acee57673b", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "eab805501886802071ad290714515c8c4a17196ea76e5afc9d06ca85fb1bfeb3"},
|
||||||
"glicko": {:hex, :glicko, "0.8.1", "3f038a9b1022116d19e33f03b95641d8a199882d718592f9b03bbdc63d55215c", [:mix], [], "hexpm", "86dc0c86f3ef442d8c0b977d377a8aed50bc732ebf4582eb1bf19b87d7bd5b1c"},
|
"glicko": {:hex, :glicko, "0.8.1", "3f038a9b1022116d19e33f03b95641d8a199882d718592f9b03bbdc63d55215c", [:mix], [], "hexpm", "86dc0c86f3ef442d8c0b977d377a8aed50bc732ebf4582eb1bf19b87d7bd5b1c"},
|
||||||
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "0435d4ca364a608cc75e2f8683d374e55abbae26", [tag: "v2.2.0", sparse: "optimized", depth: 1]},
|
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "0435d4ca364a608cc75e2f8683d374e55abbae26", [tag: "v2.2.0", sparse: "optimized", depth: 1]},
|
||||||
@@ -40,6 +41,7 @@
|
|||||||
"plug": {:hex, :plug, "1.19.2", "e4950525b22c6789dfb38a3f95d47171ba159da3fc5a33be9643b43d5e8adb98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b6fce20a56af5e60fa5dfecf3f907bb98ec981be43c79a3809a499bc3d133de0"},
|
"plug": {:hex, :plug, "1.19.2", "e4950525b22c6789dfb38a3f95d47171ba159da3fc5a33be9643b43d5e8adb98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b6fce20a56af5e60fa5dfecf3f907bb98ec981be43c79a3809a499bc3d133de0"},
|
||||||
"plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"},
|
"plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"},
|
||||||
"postgrex": {:hex, :postgrex, "0.22.2", "4aec14df2a72722aee92492566edbeeb44e233ecb86b1915d03136297ef1385d", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "8946382ddb06294f56026ac4278b3cc212bac8a2c82ed68b4087819ed1abc53b"},
|
"postgrex": {:hex, :postgrex, "0.22.2", "4aec14df2a72722aee92492566edbeeb44e233ecb86b1915d03136297ef1385d", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "8946382ddb06294f56026ac4278b3cc212bac8a2c82ed68b4087819ed1abc53b"},
|
||||||
|
"ranch": {:hex, :ranch, "2.3.0", "7de7b041a9a6a5091a3aa5898d66c0564be671d87db4f9d63b1b5ee775b097df", [:make, :rebar3], [], "hexpm", "6168ec49409d982f7cfbd83dd083144f6cbe67caa4036551d2f0a3ad67c9d023"},
|
||||||
"req": {:hex, :req, "0.6.2", "b9b2024f35bcf60a92cc8cad2eaaf9d4e7aace463ff74be1afe5986830184413", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cc9cd30a2ddd04989929b887178e1610c940456d962c6c3a52df6146d2eef9bf"},
|
"req": {:hex, :req, "0.6.2", "b9b2024f35bcf60a92cc8cad2eaaf9d4e7aace463ff74be1afe5986830184413", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cc9cd30a2ddd04989929b887178e1610c940456d962c6c3a52df6146d2eef9bf"},
|
||||||
"rustler": {:hex, :rustler, "0.38.0", "7a8906998ff0d28e3021c0a73264abcda719bda344b2e58307c6805b0f87c9b4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "704c03c1bf66be12b031c5a389347b91c81c5cb819a24b068b0de36fe4a5652a"},
|
"rustler": {:hex, :rustler, "0.38.0", "7a8906998ff0d28e3021c0a73264abcda719bda344b2e58307c6805b0f87c9b4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "704c03c1bf66be12b031c5a389347b91c81c5cb819a24b068b0de36fe4a5652a"},
|
||||||
"swoosh": {:hex, :swoosh, "1.26.1", "2989f1089e3cf1a938bbd3908c11d7dba8c8a4fe78801a7762d26f01bdbb32b4", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, ">= 1.9.0 and < 5.0.0", [hex: :hackney, repo: "hexpm", optional: true]}, {:idna, ">= 6.0.0 and < 8.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5.10 or ~> 0.6 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8ad197c025102bbcbaffcd67c10ff7b390746c32f534ff5158891b149460118e"},
|
"swoosh": {:hex, :swoosh, "1.26.1", "2989f1089e3cf1a938bbd3908c11d7dba8c8a4fe78801a7762d26f01bdbb32b4", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, ">= 1.9.0 and < 5.0.0", [hex: :hackney, repo: "hexpm", optional: true]}, {:idna, ">= 6.0.0 and < 8.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5.10 or ~> 0.6 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8ad197c025102bbcbaffcd67c10ff7b390746c32f534ff5158891b149460118e"},
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
defmodule Chesstrainer.Repo.Migrations.AddUnsubscribedAtToMailingListSubscribers do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:mailing_list_subscribers) do
|
||||||
|
add :unsubscribed_at, :utc_datetime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
defmodule Chesstrainer.Repo.Migrations.AddConfirmationSentAtToMailingListSubscribers do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:mailing_list_subscribers) do
|
||||||
|
add :confirmation_sent_at, :utc_datetime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -9,6 +9,8 @@ defmodule Chesstrainer.AccountsTest do
|
|||||||
alias Chesstrainer.Attempts
|
alias Chesstrainer.Attempts
|
||||||
alias Chesstrainer.Attempts.Attempt
|
alias Chesstrainer.Attempts.Attempt
|
||||||
alias Chesstrainer.Accounts.Scope
|
alias Chesstrainer.Accounts.Scope
|
||||||
|
alias Chesstrainer.MailingList
|
||||||
|
alias Chesstrainer.MailingList.Subscriber
|
||||||
|
|
||||||
describe "get_user_by_email/1" do
|
describe "get_user_by_email/1" do
|
||||||
test "does not return the user if the email does not exist" do
|
test "does not return the user if the email does not exist" do
|
||||||
@@ -340,6 +342,19 @@ defmodule Chesstrainer.AccountsTest do
|
|||||||
refute Repo.get_by(UserToken, user_id: user.id)
|
refute Repo.get_by(UserToken, user_id: user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "updates the linked mailing-list address", %{
|
||||||
|
user: user,
|
||||||
|
token: token,
|
||||||
|
email: email
|
||||||
|
} do
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
MailingList.confirm_user_subscription(user)
|
||||||
|
|
||||||
|
assert {:ok, %{email: ^email}} = Accounts.update_user_email(user, token)
|
||||||
|
|
||||||
|
assert %Subscriber{email: ^email} = Repo.get_by(Subscriber, user_id: user.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "does not update email with invalid token", %{user: user} do
|
test "does not update email with invalid token", %{user: user} do
|
||||||
assert Accounts.update_user_email(user, "oops") ==
|
assert Accounts.update_user_email(user, "oops") ==
|
||||||
{:error, :transaction_aborted}
|
{:error, :transaction_aborted}
|
||||||
|
|||||||
@@ -127,4 +127,172 @@ defmodule Chesstrainer.MailingListTest do
|
|||||||
Repo.get_by(Subscriber, email: "player@example.com")
|
Repo.get_by(Subscriber, email: "player@example.com")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "unsubscribe/1" do
|
||||||
|
test "marks a confirmed address as unsubscribed" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.confirm("player@example.com")
|
||||||
|
|
||||||
|
assert {:ok, %Subscriber{unsubscribed_at: unsubscribed_at}} =
|
||||||
|
MailingList.unsubscribe("player@example.com")
|
||||||
|
|
||||||
|
assert unsubscribed_at
|
||||||
|
assert MailingList.count_confirmed_subscribers() == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
test "is idempotent" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.confirm("player@example.com")
|
||||||
|
|
||||||
|
{:ok, first} = MailingList.unsubscribe("player@example.com")
|
||||||
|
{:ok, second} = MailingList.unsubscribe("player@example.com")
|
||||||
|
|
||||||
|
assert first.unsubscribed_at == second.unsubscribed_at
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns not found for an unknown address" do
|
||||||
|
assert {:error, :not_found} = MailingList.unsubscribe("nobody@example.com")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "unsubscribe_user/1" do
|
||||||
|
test "unsubscribes the address linked to the user" do
|
||||||
|
user = user_fixture()
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
MailingList.confirm_user_subscription(user)
|
||||||
|
|
||||||
|
assert {:ok, %Subscriber{unsubscribed_at: unsubscribed_at}} =
|
||||||
|
MailingList.unsubscribe_user(user)
|
||||||
|
|
||||||
|
assert unsubscribed_at
|
||||||
|
refute MailingList.user_subscribed?(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns not found when the user is not on the list" do
|
||||||
|
assert {:error, :not_found} = MailingList.unsubscribe_user(user_fixture())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "user_subscribed?/1" do
|
||||||
|
test "is true only for a confirmed, active subscription" do
|
||||||
|
user = user_fixture()
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
|
||||||
|
refute MailingList.user_subscribed?(user)
|
||||||
|
|
||||||
|
MailingList.confirm_user_subscription(user)
|
||||||
|
assert MailingList.user_subscribed?(user)
|
||||||
|
|
||||||
|
{:ok, _subscriber} = MailingList.unsubscribe_user(user)
|
||||||
|
refute MailingList.user_subscribed?(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "re-subscribing after unsubscribe" do
|
||||||
|
test "requires a fresh confirmation and clears the unsubscribe" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.confirm("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.unsubscribe("player@example.com")
|
||||||
|
|
||||||
|
assert {:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
|
||||||
|
assert {:ok, %Subscriber{confirmed_at: confirmed_at, unsubscribed_at: nil}} =
|
||||||
|
MailingList.confirm("player@example.com")
|
||||||
|
|
||||||
|
assert confirmed_at
|
||||||
|
assert MailingList.count_confirmed_subscribers() == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update_subscriber_email/2" do
|
||||||
|
test "moves the linked subscription to the new address" do
|
||||||
|
user = user_fixture()
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
MailingList.confirm_user_subscription(user)
|
||||||
|
|
||||||
|
new_email = unique_user_email()
|
||||||
|
|
||||||
|
assert {:ok, %Subscriber{email: ^new_email}} =
|
||||||
|
MailingList.update_subscriber_email(user, new_email)
|
||||||
|
|
||||||
|
assert Repo.get_by(Subscriber, user_id: user.id).email == new_email
|
||||||
|
end
|
||||||
|
|
||||||
|
test "removes an anonymous row that already holds the new address" do
|
||||||
|
user = user_fixture()
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
new_email = unique_user_email()
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe(new_email)
|
||||||
|
|
||||||
|
assert {:ok, _subscriber} = MailingList.update_subscriber_email(user, new_email)
|
||||||
|
|
||||||
|
assert Repo.aggregate(Subscriber, :count) == 1
|
||||||
|
assert %Subscriber{user_id: user_id} = Repo.get_by(Subscriber, email: new_email)
|
||||||
|
assert user_id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "keeps an unsubscribe from an anonymous row at the new address" do
|
||||||
|
user = user_fixture()
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
MailingList.confirm_user_subscription(user)
|
||||||
|
new_email = unique_user_email()
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe(new_email)
|
||||||
|
{:ok, _subscriber} = MailingList.confirm(new_email)
|
||||||
|
{:ok, _subscriber} = MailingList.unsubscribe(new_email)
|
||||||
|
|
||||||
|
assert {:ok, %Subscriber{unsubscribed_at: unsubscribed_at}} =
|
||||||
|
MailingList.update_subscriber_email(user, new_email)
|
||||||
|
|
||||||
|
assert unsubscribed_at
|
||||||
|
refute MailingList.user_subscribed?(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does nothing when the user is not on the list" do
|
||||||
|
user = user_fixture()
|
||||||
|
|
||||||
|
assert {:ok, :no_subscription} =
|
||||||
|
MailingList.update_subscriber_email(user, unique_user_email())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "confirmation cooldown" do
|
||||||
|
test "allows an address that has never received a confirmation" do
|
||||||
|
assert MailingList.confirmation_allowed?("player@example.com")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "blocks a recently sent confirmation" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.mark_confirmation_sent("player@example.com")
|
||||||
|
|
||||||
|
refute MailingList.confirmation_allowed?("player@example.com")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "allows another send after the cooldown" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
|
||||||
|
Repo.get_by(Subscriber, email: "player@example.com")
|
||||||
|
|> Ecto.Changeset.change(
|
||||||
|
confirmation_sent_at: DateTime.add(DateTime.utc_now(:second), -11, :minute)
|
||||||
|
)
|
||||||
|
|> Repo.update!()
|
||||||
|
|
||||||
|
assert MailingList.confirmation_allowed?("player@example.com")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "allows a confirmed address" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.confirm("player@example.com")
|
||||||
|
|
||||||
|
assert MailingList.confirmation_allowed?("player@example.com")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "still applies after an unsubscribe" do
|
||||||
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.confirm("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.unsubscribe("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.mark_confirmation_sent("player@example.com")
|
||||||
|
|
||||||
|
refute MailingList.confirmation_allowed?("player@example.com")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ defmodule ChesstrainerWeb.LandingComponentsTest do
|
|||||||
assert html =~ "Today’s position"
|
assert html =~ "Today’s position"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "describes the board as an image for assistive technology" do
|
||||||
|
html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame})
|
||||||
|
|
||||||
|
assert html =~ ~s(role="img")
|
||||||
|
assert html =~ "Chess position. White to move"
|
||||||
|
assert html =~ "rook on f3"
|
||||||
|
end
|
||||||
|
|
||||||
test "falls back to a neutral position without an endgame" do
|
test "falls back to a neutral position without an endgame" do
|
||||||
html = render_component(&LandingComponents.board_preview/1, %{endgame: nil})
|
html = render_component(&LandingComponents.board_preview/1, %{endgame: nil})
|
||||||
|
|
||||||
|
|||||||
@@ -31,14 +31,13 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "colour_mode_toggle/1" do
|
describe "colour_mode_toggle/1" do
|
||||||
test "renders all three modes as a labelled radiogroup" do
|
test "renders light and dark modes as a labelled radiogroup" do
|
||||||
html = render_component(&Layouts.colour_mode_toggle/1, %{})
|
html = render_component(&Layouts.colour_mode_toggle/1, %{})
|
||||||
|
|
||||||
assert html =~ ~s(role="radiogroup")
|
assert html =~ ~s(role="radiogroup")
|
||||||
assert html =~ ~s(aria-label="Colour mode")
|
assert html =~ ~s(aria-label="Colour mode")
|
||||||
|
|
||||||
for {mode, label} <- [
|
for {mode, label} <- [
|
||||||
{"system", "System colour mode"},
|
|
||||||
{"light", "Light colour mode"},
|
{"light", "Light colour mode"},
|
||||||
{"dark", "Dark colour mode"}
|
{"dark", "Dark colour mode"}
|
||||||
] do
|
] do
|
||||||
@@ -47,6 +46,7 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
|||||||
assert html =~ ~s(role="radio")
|
assert html =~ ~s(role="radio")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
refute html =~ ~s(data-phx-theme="system")
|
||||||
assert html =~ ~s(aria-checked="true")
|
assert html =~ ~s(aria-checked="true")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -57,4 +57,13 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
|||||||
assert html =~ ~s(class="nav-right")
|
assert html =~ ~s(class="nav-right")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "pill button" do
|
||||||
|
test "renders the navigation call to action as a link" do
|
||||||
|
html = render_component(&Layouts.navbar/1, %{current_scope: nil})
|
||||||
|
|
||||||
|
assert html =~ ~r/<a[^>]*class="nav-cta"/
|
||||||
|
refute html =~ ~r/<button[^>]*class="nav-cta"/
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
defmodule ChesstrainerWeb.Board.PositionTextTest do
|
||||||
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
|
alias ChesstrainerWeb.Board.PositionText
|
||||||
|
|
||||||
|
test "names the side to move and every piece" do
|
||||||
|
assert PositionText.summary("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") ==
|
||||||
|
"White to move. White: king on d3, rook on f3. Black: king on d6."
|
||||||
|
end
|
||||||
|
|
||||||
|
test "describes black to move" do
|
||||||
|
assert PositionText.summary("8/8/3k4/8/8/3K1R2/8/8 b - - 0 1") =~
|
||||||
|
"Black to move."
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes pawns and both colours" do
|
||||||
|
summary = PositionText.summary("8/8/3k4/8/8/3K1R2/4P3/8 w - - 0 1")
|
||||||
|
|
||||||
|
assert summary =~ "White: king on d3, rook on f3, pawn on e2."
|
||||||
|
assert summary =~ "Black: king on d6."
|
||||||
|
end
|
||||||
|
|
||||||
|
test "falls back when the FEN cannot be read" do
|
||||||
|
assert PositionText.summary("not a fen") == "Chess position."
|
||||||
|
assert PositionText.summary(nil) == "Chess position."
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
defmodule ChesstrainerWeb.MailingListControllerTest do
|
defmodule ChesstrainerWeb.MailingListControllerTest do
|
||||||
use ChesstrainerWeb.ConnCase, async: true
|
use ChesstrainerWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Chesstrainer.MailingList
|
||||||
alias Chesstrainer.MailingList.Subscriber
|
alias Chesstrainer.MailingList.Subscriber
|
||||||
alias Chesstrainer.Repo
|
alias Chesstrainer.Repo
|
||||||
|
alias ChesstrainerWeb.MailingListFormToken
|
||||||
|
|
||||||
@salt "mailing_list_confirm"
|
@salt "mailing_list_confirm"
|
||||||
|
|
||||||
describe "POST /mailing-list" do
|
describe "POST /mailing-list" do
|
||||||
test "sends a confirmation email for a new address", %{conn: conn} do
|
test "sends a confirmation email for a new address", %{conn: conn} do
|
||||||
conn = post(conn, ~p"/mailing-list", subscriber: %{email: "player@example.com"})
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
assert redirected_to(conn) == "/#mailing-list"
|
assert redirected_to(conn) == "/#mailing-list"
|
||||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Check your inbox"
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Check your inbox"
|
||||||
@@ -17,32 +22,140 @@ defmodule ChesstrainerWeb.MailingListControllerTest do
|
|||||||
assert_received {:email, email}
|
assert_received {:email, email}
|
||||||
assert email.subject == "Confirm your mailing list subscription"
|
assert email.subject == "Confirm your mailing list subscription"
|
||||||
assert email.text_body =~ "/mailing-list/confirm/"
|
assert email.text_body =~ "/mailing-list/confirm/"
|
||||||
|
assert email.reply_to == {"", "support@innersquare.app"}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "resends confirmation for an address that has not confirmed yet", %{conn: conn} do
|
test "re-confirms an address that previously unsubscribed", %{conn: conn} do
|
||||||
post(conn, ~p"/mailing-list", subscriber: %{email: "player@example.com"})
|
{:ok, :confirmation_required} = MailingList.subscribe("player@example.com")
|
||||||
assert_received {:email, _email}
|
{:ok, _subscriber} = MailingList.confirm("player@example.com")
|
||||||
|
{:ok, _subscriber} = MailingList.unsubscribe("player@example.com")
|
||||||
|
|
||||||
conn = post(build_conn(), ~p"/mailing-list", subscriber: %{email: "player@example.com"})
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Check your inbox"
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Check your inbox"
|
||||||
assert_received {:email, _email}
|
|
||||||
assert Repo.aggregate(Subscriber, :count) == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
test "does not email an address that has already confirmed", %{conn: conn} do
|
|
||||||
post(conn, ~p"/mailing-list", subscriber: %{email: "player@example.com"})
|
|
||||||
assert_received {:email, email}
|
assert_received {:email, email}
|
||||||
get(build_conn(), "/mailing-list/confirm/#{extract_token(email)}")
|
get(build_conn(), "/mailing-list/confirm/#{extract_token(email)}")
|
||||||
|
|
||||||
conn = post(build_conn(), ~p"/mailing-list", subscriber: %{email: "player@example.com"})
|
subscriber = Repo.get_by(Subscriber, email: "player@example.com")
|
||||||
|
assert subscriber.confirmed_at
|
||||||
|
assert subscriber.unsubscribed_at == nil
|
||||||
|
assert MailingList.count_confirmed_subscribers() == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not resend confirmation while the cooldown is active", %{conn: conn} do
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_received {:email, _email}
|
||||||
|
|
||||||
|
conn =
|
||||||
|
post(build_conn(), ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Check your inbox"
|
||||||
|
refute_received {:email, _email}
|
||||||
|
assert Repo.aggregate(Subscriber, :count) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
test "resends confirmation after the cooldown", %{conn: conn} do
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_received {:email, _email}
|
||||||
|
|
||||||
|
subscriber = Repo.get_by(Subscriber, email: "player@example.com")
|
||||||
|
|
||||||
|
subscriber
|
||||||
|
|> Ecto.Changeset.change(
|
||||||
|
confirmation_sent_at: DateTime.add(DateTime.utc_now(:second), -11, :minute)
|
||||||
|
)
|
||||||
|
|> Repo.update!()
|
||||||
|
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_received {:email, _email}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "silently accepts a honeypot submission", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{
|
||||||
|
email: "player@example.com",
|
||||||
|
company: "spam.example",
|
||||||
|
form_token: form_token()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert redirected_to(conn) == "/#mailing-list"
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Check your inbox"
|
||||||
|
refute_received {:email, _email}
|
||||||
|
assert Repo.aggregate(Subscriber, :count) == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rejects a form token submitted too quickly", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: MailingListFormToken.sign()}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "refresh the page"
|
||||||
|
refute_received {:email, _email}
|
||||||
|
assert Repo.aggregate(Subscriber, :count) == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rejects an expired form token", %{conn: conn} do
|
||||||
|
token = MailingListFormToken.sign(System.system_time(:second) - 3 * 60 * 60)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: token}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "refresh the page"
|
||||||
|
refute_received {:email, _email}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rejects an invalid form token", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: "oops"}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "refresh the page"
|
||||||
|
refute_received {:email, _email}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not email an address that has already confirmed", %{conn: conn} do
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_received {:email, email}
|
||||||
|
get(build_conn(), "/mailing-list/confirm/#{extract_token(email)}")
|
||||||
|
|
||||||
|
conn =
|
||||||
|
post(build_conn(), ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "already on the mailing list"
|
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "already on the mailing list"
|
||||||
refute_received {:email, _email}
|
refute_received {:email, _email}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "reports an invalid address", %{conn: conn} do
|
test "reports an invalid address", %{conn: conn} do
|
||||||
conn = post(conn, ~p"/mailing-list", subscriber: %{email: "not an email"})
|
conn =
|
||||||
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "not an email", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
assert redirected_to(conn) == "/#mailing-list"
|
assert redirected_to(conn) == "/#mailing-list"
|
||||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "valid email address"
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "valid email address"
|
||||||
@@ -60,7 +173,10 @@ defmodule ChesstrainerWeb.MailingListControllerTest do
|
|||||||
|
|
||||||
describe "GET /mailing-list/confirm/:token" do
|
describe "GET /mailing-list/confirm/:token" do
|
||||||
test "confirms the subscription from the emailed link", %{conn: conn} do
|
test "confirms the subscription from the emailed link", %{conn: conn} do
|
||||||
post(conn, ~p"/mailing-list", subscriber: %{email: "player@example.com"})
|
post(conn, ~p"/mailing-list",
|
||||||
|
subscriber: %{email: "player@example.com", form_token: form_token()}
|
||||||
|
)
|
||||||
|
|
||||||
assert_received {:email, email}
|
assert_received {:email, email}
|
||||||
|
|
||||||
conn = get(build_conn(), "/mailing-list/confirm/#{extract_token(email)}")
|
conn = get(build_conn(), "/mailing-list/confirm/#{extract_token(email)}")
|
||||||
@@ -107,4 +223,8 @@ defmodule ChesstrainerWeb.MailingListControllerTest do
|
|||||||
[_, token] = Regex.run(~r{/mailing-list/confirm/(\S+)}, email.text_body)
|
[_, token] = Regex.run(~r{/mailing-list/confirm/(\S+)}, email.text_body)
|
||||||
token
|
token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp form_token do
|
||||||
|
MailingListFormToken.sign(System.system_time(:second) - 5)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
|||||||
refute html =~ "Phoenix Framework"
|
refute html =~ "Phoenix Framework"
|
||||||
|
|
||||||
eyebrow = LazyHTML.query(document, ".eyebrow")
|
eyebrow = LazyHTML.query(document, ".eyebrow")
|
||||||
assert LazyHTML.text(eyebrow) =~ "Endgames, made clear"
|
assert LazyHTML.text(eyebrow) =~ "Endgames, simplified"
|
||||||
assert LazyHTML.attribute(LazyHTML.query(eyebrow, "svg"), "aria-hidden") == ["true"]
|
assert LazyHTML.attribute(LazyHTML.query(eyebrow, "svg"), "aria-hidden") == ["true"]
|
||||||
|
|
||||||
assert LazyHTML.attribute(LazyHTML.query(document, ~s(meta[name="description"])), "content") ==
|
assert LazyHTML.attribute(LazyHTML.query(document, ~s(meta[name="description"])), "content") ==
|
||||||
@@ -194,6 +194,9 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
|||||||
|
|
||||||
assert html =~ "Join the list"
|
assert html =~ "Join the list"
|
||||||
assert html =~ ~s(name="_csrf_token")
|
assert html =~ ~s(name="_csrf_token")
|
||||||
|
assert html =~ ~s(name="subscriber[form_token]")
|
||||||
|
assert html =~ ~s(id="mailing-list-company")
|
||||||
|
assert html =~ ~s(class="mailing-list-honeypot")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "guest navbar links to log in and register", %{conn: conn} do
|
test "guest navbar links to log in and register", %{conn: conn} do
|
||||||
@@ -216,19 +219,13 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
|||||||
refute html =~ ~p"/users/register"
|
refute html =~ ~p"/users/register"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders curated cards and the daily board", %{conn: conn} do
|
test "renders the daily board", %{conn: conn} do
|
||||||
{beginner, intermediate, advanced} = curated!()
|
curated!()
|
||||||
daily = DailyPuzzles.today()
|
daily = DailyPuzzles.today()
|
||||||
|
|
||||||
html = conn |> get(~p"/") |> html_response(200)
|
html = conn |> get(~p"/") |> html_response(200)
|
||||||
document = LazyHTML.from_document(html)
|
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"))
|
board = LazyHTML.text(LazyHTML.query(document, ".board-caption"))
|
||||||
assert board =~ daily.key
|
assert board =~ daily.key
|
||||||
|
|
||||||
@@ -238,7 +235,6 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
|||||||
|
|
||||||
assert LazyHTML.text(LazyHTML.query(document, ".board-topline")) =~ "White"
|
assert LazyHTML.text(LazyHTML.query(document, ".board-topline")) =~ "White"
|
||||||
assert html =~ "Try today's puzzle"
|
assert html =~ "Try today's puzzle"
|
||||||
assert html =~ "<span>puzzles</span>"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "hero CTA links to the daily puzzle", %{conn: conn} do
|
test "hero CTA links to the daily puzzle", %{conn: conn} do
|
||||||
@@ -274,7 +270,6 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
|||||||
document = LazyHTML.from_document(html)
|
document = LazyHTML.from_document(html)
|
||||||
|
|
||||||
assert html =~ "Featured position"
|
assert html =~ "Featured position"
|
||||||
assert html =~ "<span>puzzles</span>"
|
|
||||||
refute html =~ "puzzle-card"
|
refute html =~ "puzzle-card"
|
||||||
|
|
||||||
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
|
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
|
||||||
|
|||||||
@@ -961,7 +961,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
|||||||
assert_receive {^ref, {:push_event, "review_position", _}}, 100
|
assert_receive {^ref, {:push_event, "review_position", _}}, 100
|
||||||
assert_receive {^ref, {:push_event, "review_position", _}}, 100
|
assert_receive {^ref, {:push_event, "review_position", _}}, 100
|
||||||
|
|
||||||
view |> element("#best-move-panel tr[phx-value-uci='d1d5']") |> render_click()
|
view |> element("#best-move-panel button[phx-value-uci='d1d5']") |> render_click()
|
||||||
|
|
||||||
assert_receive {^ref, {:push_event, "best_line_move", %{from: "d1", to: "d5"}}}, 100
|
assert_receive {^ref, {:push_event, "best_line_move", %{from: "d1", to: "d5"}}}, 100
|
||||||
|
|
||||||
@@ -1044,4 +1044,84 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
|||||||
assert panel =~ "Qd7+"
|
assert panel =~ "Qd7+"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "keyboard move input" do
|
||||||
|
defp open_with_moves(conn) do
|
||||||
|
endgame = endgame_fixture()
|
||||||
|
seed_tablebase(endgame.fen, moves: grading_moves())
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
||||||
|
view
|
||||||
|
end
|
||||||
|
|
||||||
|
test "accepts SAN and asks the board to apply it", %{conn: conn} do
|
||||||
|
view = open_with_moves(conn)
|
||||||
|
%{proxy: {ref, _topic, _}} = view
|
||||||
|
|
||||||
|
view |> form("#move-input-form", move: "Qd7+") |> render_submit()
|
||||||
|
|
||||||
|
assert_receive {^ref, {:push_event, "apply_move", %{from: "d1", to: "d7", san: "Qd7+"}}},
|
||||||
|
100
|
||||||
|
end
|
||||||
|
|
||||||
|
test "accepts UCI", %{conn: conn} do
|
||||||
|
view = open_with_moves(conn)
|
||||||
|
%{proxy: {ref, _topic, _}} = view
|
||||||
|
|
||||||
|
view |> form("#move-input-form", move: "d1d5") |> render_submit()
|
||||||
|
|
||||||
|
assert_receive {^ref, {:push_event, "apply_move", %{from: "d1", to: "d5"}}}, 100
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reports an illegal move without asking the board to play it", %{conn: conn} do
|
||||||
|
view = open_with_moves(conn)
|
||||||
|
%{proxy: {ref, _topic, _}} = view
|
||||||
|
|
||||||
|
html = view |> form("#move-input-form", move: "Qh8") |> render_submit()
|
||||||
|
|
||||||
|
assert html =~ "Not a legal move here"
|
||||||
|
refute_receive {^ref, {:push_event, "apply_move", _}}, 100
|
||||||
|
end
|
||||||
|
|
||||||
|
test "labels the input and explains both move formats", %{conn: conn} do
|
||||||
|
view = open_with_moves(conn)
|
||||||
|
|
||||||
|
assert has_element?(view, "label[for='move-input']", "Your move")
|
||||||
|
assert has_element?(view, "#move-input-help", "SAN or UCI")
|
||||||
|
assert has_element?(view, "#move-input[aria-describedby='move-input-help']")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "screen reader announcements" do
|
||||||
|
test "announces the opening position and whose move it is", %{conn: conn} do
|
||||||
|
endgame = endgame_fixture()
|
||||||
|
seed_tablebase(endgame.fen)
|
||||||
|
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
||||||
|
|
||||||
|
announcer = view |> element("#board-announcer") |> render()
|
||||||
|
assert announcer =~ "You play White."
|
||||||
|
assert announcer =~ "White to move."
|
||||||
|
|
||||||
|
summary = view |> element("#position-summary") |> render()
|
||||||
|
assert summary =~ "king on"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "announces a failed puzzle and the best move", %{conn: conn} do
|
||||||
|
{view, _fens} = seeded_attempt(conn)
|
||||||
|
|
||||||
|
announcer = view |> element("#board-announcer") |> render()
|
||||||
|
assert announcer =~ "Failed."
|
||||||
|
assert announcer =~ "Best was"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "announces the reviewed position", %{conn: conn} do
|
||||||
|
{view, _fens} = seeded_attempt(conn)
|
||||||
|
|
||||||
|
view |> element("button", "Review") |> render_click()
|
||||||
|
|
||||||
|
announcer = view |> element("#board-announcer") |> render()
|
||||||
|
assert announcer =~ "Reviewing position"
|
||||||
|
assert announcer =~ "After Qd4"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ defmodule ChesstrainerWeb.EndgameLive.TrainTest do
|
|||||||
assert has_element?(view, "#difficulty-medium")
|
assert has_element?(view, "#difficulty-medium")
|
||||||
assert has_element?(view, "#difficulty-hard")
|
assert has_element?(view, "#difficulty-hard")
|
||||||
assert has_element?(view, "#close-difficulty[href='/']")
|
assert has_element?(view, "#close-difficulty[href='/']")
|
||||||
assert has_element?(view, "a", "Cancel")
|
assert has_element?(view, "a", "Return Home")
|
||||||
refute has_element?(view, "#puzzle-search")
|
refute has_element?(view, "#puzzle-search")
|
||||||
assert has_element?(view, "#rating-guide")
|
assert has_element?(view, "#rating-guide")
|
||||||
assert render(view) =~ "Choose a difficulty"
|
assert render(view) =~ "Choose a difficulty"
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ defmodule ChesstrainerWeb.UserLive.ProfileTest do
|
|||||||
alias Chesstrainer.Accounts
|
alias Chesstrainer.Accounts
|
||||||
alias Chesstrainer.Accounts.Scope
|
alias Chesstrainer.Accounts.Scope
|
||||||
alias Chesstrainer.Attempts
|
alias Chesstrainer.Attempts
|
||||||
|
alias Chesstrainer.MailingList
|
||||||
|
alias Chesstrainer.MailingList.Subscriber
|
||||||
|
alias Chesstrainer.Repo
|
||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest
|
||||||
import Chesstrainer.AccountsFixtures
|
import Chesstrainer.AccountsFixtures
|
||||||
import Chesstrainer.EndgamesFixtures
|
import Chesstrainer.EndgamesFixtures
|
||||||
@@ -303,4 +306,38 @@ defmodule ChesstrainerWeb.UserLive.ProfileTest do
|
|||||||
assert message == "You must log in to access this page."
|
assert message == "You must log in to access this page."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "mailing list settings" do
|
||||||
|
setup %{conn: conn} do
|
||||||
|
user = user_fixture()
|
||||||
|
%{conn: log_in_user(conn, user), user: user}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows the not-subscribed state", %{conn: conn} do
|
||||||
|
{:ok, view, html} = live(conn, ~p"/users/profile/settings")
|
||||||
|
|
||||||
|
assert has_element?(view, "#mailing-list-settings")
|
||||||
|
assert html =~ "not subscribed"
|
||||||
|
refute has_element?(view, "#unsubscribe-mailing-list")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unsubscribes a subscribed user", %{conn: conn, user: user} do
|
||||||
|
{:ok, _subscriber} = MailingList.subscribe_user(user)
|
||||||
|
MailingList.confirm_user_subscription(user)
|
||||||
|
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/users/profile/settings")
|
||||||
|
|
||||||
|
assert has_element?(view, "#unsubscribe-mailing-list")
|
||||||
|
|
||||||
|
html = view |> element("#unsubscribe-mailing-list") |> render_click()
|
||||||
|
|
||||||
|
assert html =~ "removed from the mailing list"
|
||||||
|
refute has_element?(view, "#unsubscribe-mailing-list")
|
||||||
|
|
||||||
|
assert %Subscriber{unsubscribed_at: unsubscribed_at} =
|
||||||
|
Repo.get_by(Subscriber, user_id: user.id)
|
||||||
|
|
||||||
|
assert unsubscribed_at
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user