diff --git a/CLAUDE.md b/CLAUDE.md
index e81254f..218e9e9 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -15,3 +15,7 @@ npm run build
```
The steps are defined in `.github/workflows/ci.yml`. A failure blocks the deploy job and emails the owner. It happened once after running only tsc and vitest: eslint (`react-hooks/purity`, `performance.now` in a component) and prettier (a SCSS file) both failed in CI.
+
+## While iterating
+
+When making changes with the owner in a back-and-forth session, don't run the test suite (or the rest of the CI steps) after each change, unless they ask for it. The tests take long enough to slow the iteration down significantly. Update the tests alongside the code as usual, so that they are right when they do get run, and say that they haven't been run. The full CI run before a push (above) still applies.
diff --git a/web/index.html b/web/index.html
index b0f1115..c4718ba 100644
--- a/web/index.html
+++ b/web/index.html
@@ -1,7 +1,7 @@
-
+
diff --git a/web/public/favicon.svg b/web/public/favicon.svg
new file mode 100644
index 0000000..11e4c5f
--- /dev/null
+++ b/web/public/favicon.svg
@@ -0,0 +1,6 @@
+
diff --git a/web/src/App.test.tsx b/web/src/App.test.tsx
index 8d0b50d..01b9eec 100644
--- a/web/src/App.test.tsx
+++ b/web/src/App.test.tsx
@@ -1,10 +1,9 @@
-import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import App from "@/App";
import { defaultColors } from "@/config";
import { createDemoGame } from "@/demoGame";
-import { DEFAULT_GAME_NAME } from "@/Game";
import { lastRound, partialScores, totalScore, totalScoreRange } from "@/utils/Scores";
type User = ReturnType;
@@ -32,14 +31,14 @@ async function addSecondPlayer(user: User, container: HTMLElement) {
describe("demo game", () => {
it("is only loaded when the URL asks for it", () => {
renderApp("/");
- expect(screen.queryByText("Friday Night Rummy")).toBeNull();
+ expect(screen.queryByRole("button", { name: /Continue Game/ })).toBeNull();
});
it("loads with ?demo, and plays from its latest round", async () => {
const user = userEvent.setup();
const { container } = renderApp("/?demo");
- expect(screen.getByText("Friday Night Rummy")).toBeTruthy();
+ expect(screen.getByRole("button", { name: /Continue Game/ })).toBeTruthy();
await user.click(screen.getByText("Continue Game"));
const demo = createDemoGame();
@@ -112,7 +111,7 @@ describe("demo game", () => {
});
describe("title page", () => {
- it("starts a new game with one player, in edit mode", async () => {
+ it("starts a new game with one player, with the window for editing the players open", async () => {
const user = userEvent.setup();
const { container } = renderApp("/");
@@ -121,31 +120,7 @@ describe("title page", () => {
expect(container.querySelectorAll(".player")).toHaveLength(1);
expect(container.querySelector(".player-name-input")!.value).toBe("Player 1");
expect(screen.getByText("Edit Players")).toBeTruthy();
- expect(container.querySelector(".player.editing")).not.toBeNull();
- });
-
- it("starts a new game with the game name selected", async () => {
- const user = userEvent.setup();
- const { container } = renderApp("/");
-
- await user.click(screen.getByText("Start New Game"));
-
- const input = container.querySelector(".game-name-input")!;
- expect(document.activeElement).toBe(input);
- expect([input.selectionStart, input.selectionEnd]).toEqual([0, input.value.length]);
-
- // Typing replaces the whole name
- await user.keyboard("Rummy");
- expect(input.value).toBe("Rummy");
- });
-
- it("does not select the game name when entering edit mode later", async () => {
- const user = userEvent.setup();
- const { container } = renderApp();
-
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
-
- expect(document.activeElement).not.toBe(container.querySelector(".game-name-input"));
+ expect(container.querySelector(".edit-players-dialog")).not.toBeNull();
});
it("starts a new game even after playing one", async () => {
@@ -176,7 +151,6 @@ describe("title page", () => {
expect(screen.getByRole("button", { name: "Start New Game" }).classList).toContain("primary");
const continueButton = screen.getByRole("button", { name: /Continue Game/ });
expect(continueButton.classList).not.toContain("primary");
- expect(continueButton.textContent).toContain("Friday Night Rummy");
expect(continueButton.textContent).toContain(`${createDemoGame().scorecards.length} players`);
expect(demo.container.querySelectorAll(".score-lines-backdrop polyline")).toHaveLength(5);
});
@@ -190,15 +164,14 @@ describe("title page", () => {
await user.click(screen.getByText("Continue Game"));
expect(container.querySelector(".game-play-background")).not.toBeNull();
- expect(container.querySelector(".player.editing")).toBeNull();
+ expect(container.querySelector(".edit-players-dialog")).toBeNull();
expect(screen.queryByText("Edit Players")).toBeNull();
});
});
describe("game play page", () => {
- it("renders the player and the game name", () => {
+ it("renders the player", () => {
renderApp();
- expect(screen.getByText("New Game (click to edit)")).toBeTruthy();
expect(screen.getByText("Player 1")).toBeTruthy();
});
@@ -213,7 +186,7 @@ describe("game play page", () => {
const user = userEvent.setup();
const { container } = renderApp();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".add-player-button")!);
const input = document.activeElement as HTMLInputElement;
@@ -221,49 +194,28 @@ describe("game play page", () => {
expect(input.value).toBe("Player 2");
});
- it("shows player names as plain text normally and as text boxes in edit mode", async () => {
+ it("shows player names as plain text in the list, and as text boxes in the window for editing them", async () => {
const user = userEvent.setup();
const { container } = renderApp();
expect(container.querySelector(".player-name-input")).toBeNull();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
expect(container.querySelector(".player-name-input")!.value).toBe("Player 1");
- // The game name is not part of edit mode
- expect(container.querySelector(".game-name-input")).toBeNull();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".done-button")!);
expect(container.querySelector(".player-name-input")).toBeNull();
});
- it("renames the game by pressing its name, whether or not players are being edited", async () => {
- const user = userEvent.setup();
- const { container } = renderApp();
-
- await user.click(container.querySelector(".game-name-label")!);
- const input = container.querySelector(".game-name-input")!;
- expect(input.value).toBe("New Game (click to edit)");
- expect(container.querySelector(".player-name-input")).toBeNull(); // Not editing the players
-
- await user.clear(input);
- await user.type(input, "Rummy{Enter}");
- expect(container.querySelector(".game-name-input")).toBeNull();
- expect(screen.getByText("Rummy")).toBeTruthy();
- });
-
- it("renames the game and players from their text boxes", async () => {
+ it("renames players from their text boxes", async () => {
const user = userEvent.setup();
const { container } = renderApp();
- await user.click(container.querySelector(".game-name-label")!);
- await user.clear(container.querySelector(".game-name-input")!);
- await user.type(container.querySelector(".game-name-input")!, "Rummy{Enter}");
await user.click(container.querySelector(".edit-players-button")!);
await user.clear(container.querySelector(".player-name-input")!);
await user.type(container.querySelector(".player-name-input")!, "Ada{Enter}");
await user.click(container.querySelector(".done-button")!);
- expect(screen.getByText("Rummy")).toBeTruthy();
expect(screen.getByText("Ada")).toBeTruthy();
});
@@ -394,6 +346,47 @@ describe("game play page", () => {
expect(container.querySelector(".score-value")!.textContent).toBe("55");
});
+ it("shows a key of the keypad as pressed while its key on the keyboard is held down", () => {
+ vi.useFakeTimers();
+ try {
+ const { container } = renderApp();
+ const pressed = () =>
+ Array.from(container.querySelectorAll(".key.pressed")).map((el) => el.className);
+
+ fireEvent.keyDown(window, { key: "5" });
+ expect(key(container, "5").classList.contains("pressed")).toBe(true);
+ fireEvent.keyUp(window, { key: "5" }); // A quick tap: it stays pressed a moment longer
+ expect(key(container, "5").classList.contains("pressed")).toBe(true);
+ act(() => vi.advanceTimersByTime(200));
+ expect(pressed()).toEqual([]);
+
+ for (const [pressedKey, keypadClass] of [
+ ["-", "key-negate"],
+ ["Backspace", "key-backspace"],
+ ["Enter", "key-enter"],
+ [".", "key-point"],
+ ] as const) {
+ fireEvent.keyDown(window, { key: pressedKey });
+ expect(container.querySelector(`.${keypadClass}`)!.classList.contains("pressed")).toBe(
+ true,
+ );
+ fireEvent.keyUp(window, { key: pressedKey });
+ act(() => vi.advanceTimersByTime(200));
+ }
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it("does not show a key as pressed for a key of the keyboard that has no key on the keypad", () => {
+ const { container } = renderApp();
+
+ fireEvent.keyDown(window, { key: "ArrowDown" });
+ fireEvent.keyDown(window, { key: "x" });
+
+ expect(container.querySelectorAll(".key.pressed")).toHaveLength(0);
+ });
+
it("only ever shows one key as pressed", () => {
const { container } = renderApp();
@@ -430,13 +423,12 @@ describe("game play page", () => {
const user = userEvent.setup();
const { container } = renderApp();
await user.click(container.querySelector(".edit-players-button")!);
- const list = container.querySelector(".player-list")!;
- const footer = container.querySelector(".list-footer")!;
+ const list = container.querySelector(".edit-players-list")!;
+ const footer = container.querySelector(".edit-players-footer")!;
expect(footer.querySelector(".add-player-button")).not.toBeNull();
expect(list.contains(footer)).toBe(false);
expect(footer.parentElement).toBe(list.parentElement);
- expect(container.querySelector(".round-buttons")!.parentElement).toBe(list.parentElement);
});
it("scrolls the next player into view when the keypad moves on to them", async () => {
@@ -450,7 +442,9 @@ describe("game play page", () => {
const rows = container.querySelectorAll(".player");
const lastCall = scrollIntoView.mock.contexts.length - 1;
expect(scrollIntoView.mock.contexts[lastCall]).toBe(rows[1]);
- expect(scrollIntoView.mock.calls[lastCall]).toEqual([{ block: "nearest" }]);
+ expect(scrollIntoView.mock.calls[lastCall]).toEqual([
+ { block: "center", behavior: "smooth" },
+ ]);
});
it("scrolls to the player entered on, after a score moves the selection along", async () => {
@@ -469,7 +463,7 @@ describe("game play page", () => {
it("doesn't scroll around in edit mode", async () => {
const user = userEvent.setup();
const { container } = renderApp();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
const scrollIntoView = spyOnScrollIntoView();
fireEvent.keyDown(window, { key: "ArrowDown" });
@@ -507,9 +501,9 @@ describe("game play page", () => {
function openLongList() {
const view = renderApp("/?demo");
fireEvent.click(screen.getByText("Continue Game"));
- fireEvent.click(view.container.querySelector(".done-button, .edit-players-button")!);
+ fireEvent.click(view.container.querySelector(".edit-players-button")!);
- const list = view.container.querySelector(".player-list")!;
+ const list = view.container.querySelector(".edit-players-list")!;
list.getBoundingClientRect = () => rect(listTop, listBottom - listTop);
// jsdom doesn't scroll, so keep track of how far the list has been scrolled
Object.defineProperty(list, "scrollTop", {
@@ -519,7 +513,7 @@ describe("game play page", () => {
list.dispatchEvent(new Event("scroll"));
},
});
- const rows = () => Array.from(view.container.querySelectorAll(".player"));
+ const rows = () => Array.from(view.container.querySelectorAll(".edit-player"));
for (const row of rows()) {
row.getBoundingClientRect = () => rect(rows().indexOf(row) * rowHeight, rowHeight - 4);
}
@@ -661,8 +655,8 @@ describe("game play page", () => {
async function openPickerWithSwatchAt(y: number) {
const user = userEvent.setup();
const view = renderApp();
- await user.click(view.container.querySelector(".done-button, .edit-players-button")!);
- const swatch = view.container.querySelector(".player-color")!;
+ await user.click(view.container.querySelector(".edit-players-button")!);
+ const swatch = view.container.querySelector(".edit-player .player-color")!;
swatch.getBoundingClientRect = () =>
({
x: 40,
@@ -682,7 +676,7 @@ describe("game play page", () => {
Object.defineProperty(window, "innerHeight", { value: 800, configurable: true });
});
- it("stays in edit mode while choosing a color and when closing the picker", async () => {
+ it("keeps the window open while choosing a color and when closing the picker", async () => {
const user = userEvent.setup();
const picker = await openPickerWithSwatchAt(300);
await user.click(picker.querySelector(".color-card")!);
@@ -691,14 +685,25 @@ describe("game play page", () => {
expect(document.querySelector(".done-button")).not.toBeNull();
});
+ it("can be closed with its own Done button, which the phone layout shows", async () => {
+ const user = userEvent.setup();
+ await openPickerWithSwatchAt(300);
+ const background = document.querySelector(".color-select-background")!;
+
+ await user.click(screen.getByRole("button", { name: "Close color picker" }));
+ // It fades out first, and is taken away once that is over, which jsdom has no way to say
+ expect(background.classList).toContain("closing");
+ expect(document.querySelector(".edit-players-dialog")).not.toBeNull(); // Only the picker
+ });
+
it("sits next to the color it is for", async () => {
const picker = await openPickerWithSwatchAt(300);
- expect(picker.style.top).toBe("265px");
+ expect(picker.style.top).toBe("185px"); // The middle of the 40 high color, 320, less half of 270
});
it("stays on the screen when the color is near the bottom", async () => {
const picker = await openPickerWithSwatchAt(780);
- expect(picker.style.top).toBe("686px"); // 800 high, minus the picker's 102 and a 12 margin
+ expect(picker.style.top).toBe("518px"); // 800 high, minus the picker's 270 and a 12 margin
});
it("stays on the screen when the color is near the top", async () => {
@@ -712,7 +717,7 @@ describe("game play page", () => {
const user = userEvent.setup();
const { container } = renderApp();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".player-name-input")!);
await user.keyboard("7{Enter}");
@@ -862,16 +867,16 @@ describe("game play page", () => {
it("says how", async () => {
await playTwoRounds();
- expect(screen.getByText("Tap a score to edit it")).toBeTruthy();
+ expect(screen.getByText("Click a score to edit it")).toBeTruthy();
});
});
it("says so when there are no players", async () => {
const user = userEvent.setup();
const { container } = renderApp();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".delete-button")!);
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".done-button")!);
await user.click(container.querySelectorAll(".buttons-section button")[2]!);
// The player list says something of its own, so look at the table's
@@ -1147,11 +1152,11 @@ describe("game play page", () => {
const user = userEvent.setup();
const { container } = renderApp();
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
for (const button of Array.from(container.querySelectorAll(".delete-button"))) {
await user.click(button);
}
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".done-button")!);
await user.click(container.querySelectorAll(".buttons-section button")[1]!);
expect(container.querySelector(".plot-scores-content")).not.toBeNull();
@@ -1182,17 +1187,12 @@ describe("saving the game", () => {
it("brings the game back after a reload, and Continue Game picks it up", async () => {
const user = userEvent.setup();
const first = renderApp("/play/");
- await user.click(first.container.querySelector(".game-name-label")!);
- await user.clear(first.container.querySelector(".game-name-input")!);
- await user.type(first.container.querySelector(".game-name-input")!, "Rummy");
- await user.keyboard("{Enter}");
fireEvent.keyDown(window, { key: "9" });
fireEvent.keyDown(window, { key: "Enter" });
first.unmount(); // Closing the page
const second = renderApp("/");
expect(continueButton().hasAttribute("disabled")).toBe(false);
- expect(screen.getByText("Rummy")).toBeTruthy();
await user.click(screen.getByText("Continue Game"));
expect(shownScores(second.container)).toEqual(["9"]);
});
@@ -1207,7 +1207,6 @@ describe("saving the game", () => {
const second = renderApp("/");
await user.click(screen.getByText("Start New Game"));
- expect(savedGame().game.name).toBe(DEFAULT_GAME_NAME);
expect(savedGame().game.scorecards[0].scores).toEqual([0]);
expect(second.container.querySelectorAll(".player")).toHaveLength(1);
});
@@ -1234,14 +1233,15 @@ describe("saving the game", () => {
const before = localStorage.getItem("scoreplot.game");
const { container } = renderApp("/?demo");
- expect(screen.getByText("Friday Night Rummy")).toBeTruthy();
- expect(screen.queryByText("My Real Game")).toBeNull();
+ expect(screen.getByRole("button", { name: /Continue Game/ }).textContent).toContain(
+ `${createDemoGame().scorecards.length} players`,
+ );
// Play: the "?demo" has gone from the address by now, but it is still the demo game
await user.click(screen.getByText("Continue Game"));
fireEvent.keyDown(window, { key: "4" });
fireEvent.keyDown(window, { key: "Enter" });
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".add-player-button")!);
expect(localStorage.getItem("scoreplot.game")).toBe(before);
@@ -1275,15 +1275,15 @@ describe("undoing", () => {
async function threePlayers() {
const user = userEvent.setup();
const view = renderApp("/play/");
- await user.click(view.container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(view.container.querySelector(".edit-players-button")!);
await user.click(view.container.querySelector(".add-player-button")!);
await user.click(view.container.querySelector(".add-player-button")!);
- await user.click(view.container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(view.container.querySelector(".done-button")!);
for (const score of ["4", "5", "6"]) {
fireEvent.keyDown(window, { key: score });
fireEvent.keyDown(window, { key: "Enter" });
}
- await user.click(view.container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(view.container.querySelector(".edit-players-button")!);
return { user, ...view };
}
@@ -1309,7 +1309,7 @@ describe("undoing", () => {
expect(
container.querySelectorAll(".player-color")[1]!.style.backgroundColor,
).toBe(colorBefore);
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
expect(shownScores(container)).toEqual(["4", "5", "6"]);
expect(toastMessages()).toEqual([]);
});
@@ -1343,88 +1343,328 @@ describe("undoing", () => {
});
describe("starting a new game", () => {
- /** The title page, after playing a game called Rummy in which Player 1 scored 8 */
- async function afterPlayingRummy() {
+ it("does not offer to undo it, even over a game that was played", async () => {
const user = userEvent.setup();
const first = renderApp("/play/");
- await user.click(first.container.querySelector(".game-name-label")!);
- await user.clear(first.container.querySelector(".game-name-input")!);
- await user.type(first.container.querySelector(".game-name-input")!, "Rummy");
- await user.keyboard("{Enter}");
fireEvent.keyDown(window, { key: "8" });
fireEvent.keyDown(window, { key: "Enter" });
first.unmount();
- return { user, ...renderApp("/") };
- }
-
- it("says so, with a way to undo it, over the game that was started", async () => {
- const { user, container } = await afterPlayingRummy();
+ const { container } = renderApp("/");
await user.click(screen.getByText("Start New Game"));
- expect(toastMessages()).toEqual(["Started a new game"]);
+ expect(toastMessages()).toEqual([]);
expect(container.querySelector(".game-play-background")).not.toBeNull();
- expect(container.querySelectorAll(".player")).toHaveLength(1);
expect(shownScores(container)).toEqual(["0"]);
});
- it("brings back the game that was there before", async () => {
- const { user, container } = await afterPlayingRummy();
- const savedName = () => JSON.parse(localStorage.getItem("scoreplot.game")!).game.name;
+ it("selects the first player's name in the window that opens, ready to be typed over", async () => {
+ const user = userEvent.setup();
+ renderApp("/");
await user.click(screen.getByText("Start New Game"));
- expect(savedName()).toBe(DEFAULT_GAME_NAME);
- await user.click(screen.getByRole("button", { name: "Undo" }));
- expect(savedName()).toBe("Rummy");
- await user.click(container.querySelector(".done-button, .edit-players-button")!); // Out of edit mode, as new games start in it
- expect(shownScores(container)).toEqual(["8"]);
- expect(container.querySelector(".game-name-label")!.textContent).toBe("Rummy");
+ const input = document.querySelector(".player-name-input")!;
+ expect(document.activeElement).toBe(input);
+ expect([input.selectionStart, input.selectionEnd]).toEqual([0, input.value.length]);
+ await user.keyboard("Ada");
+ expect(input.value).toBe("Ada");
});
- it("does not bother when there was nothing to lose", async () => {
+ it("selects a name that is pressed, ready to be typed over", async () => {
const user = userEvent.setup();
- renderApp("/");
- await user.click(screen.getByText("Start New Game"));
- expect(toastMessages()).toEqual([]);
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+ const input = container.querySelector(".player-name-input")!;
+
+ await user.click(input);
+
+ expect(document.activeElement).toBe(input);
+ expect([input.selectionStart, input.selectionEnd]).toEqual([0, input.value.length]);
});
- it("does not bother when the game had not been touched", async () => {
+ it("does not select a name that is tapped, as that brings up the phone's menu for a selection", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+ const input = container.querySelector(".player-name-input")!;
+
+ await user.pointer({ keys: "[TouchA]", target: input });
+
+ expect(document.activeElement).toBe(input);
+ expect(input.selectionStart).toBe(input.selectionEnd);
+ });
+
+ it("does not select a name that is tapped while another name has the focus", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+ await user.click(container.querySelector(".add-player-button")!); // The new name has the focus
+ const [first, second] = Array.from(
+ container.querySelectorAll(".player-name-input"),
+ );
+
+ await user.pointer({ keys: "[TouchA]", target: first! });
+ expect(document.activeElement).toBe(first);
+ expect(first!.selectionStart).toBe(first!.selectionEnd);
+
+ await user.pointer({ keys: "[TouchA]", target: second! });
+ expect(document.activeElement).toBe(second);
+ expect(second!.selectionStart).toBe(second!.selectionEnd);
+ });
+
+ it("selects a name for the new game only, and not when the window is opened again", async () => {
const user = userEvent.setup();
const { container } = renderApp("/");
- await user.click(screen.getByText("Start New Game")); // A game, but a blank one
- await user.click(container.querySelector(".button-home")!);
await user.click(screen.getByText("Start New Game"));
- expect(toastMessages()).toEqual([]);
+ expect(document.activeElement).toBe(container.querySelector(".player-name-input"));
+
+ await user.click(container.querySelector(".done-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
+
+ expect(document.activeElement).toBe(container.querySelector(".edit-players-dialog"));
+ });
+
+ it("does not select a name when the window is opened with the button", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+
+ await user.click(container.querySelector(".edit-players-button")!);
+
+ expect(document.activeElement).toBe(container.querySelector(".edit-players-dialog"));
});
});
});
describe("pressing a toast while editing", () => {
- it("does not leave edit mode, so that you can go on editing after an Undo", async () => {
+ it("does not close the window for editing, so that you can go on editing after an Undo", async () => {
const user = userEvent.setup();
const { container } = renderApp("/play/");
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".add-player-button")!);
await user.click(container.querySelectorAll(".delete-button")[1]!);
expect(container.querySelector(".toast")).not.toBeNull();
await user.click(screen.getByRole("button", { name: "Undo" }));
- expect(container.querySelectorAll(".player.editing")).toHaveLength(2);
+ expect(container.querySelectorAll(".edit-player")).toHaveLength(2);
expect(container.querySelector(".add-player-button")).not.toBeNull();
});
- it("still leaves edit mode for a press anywhere else", async () => {
+ it("does not close the window for a press on the page behind it", async () => {
const user = userEvent.setup();
const { container } = renderApp("/play/");
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".add-player-button")!);
await user.click(container.querySelectorAll(".delete-button")[1]!);
- await user.click(container.querySelector(".content-section")!);
+ await user.click(container.querySelector(".edit-players-backdrop")!);
+
+ expect(container.querySelector(".edit-players-dialog")).not.toBeNull();
+ });
+});
+
+describe("closing the window for editing players", () => {
+ it("closes with Escape", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+
+ await user.keyboard("{Escape}");
+
+ expect(container.querySelector(".edit-players-dialog")).toBeNull();
+ });
+
+ it("closes with Done", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
- expect(container.querySelector(".player.editing")).toBeNull();
+ await user.click(container.querySelector(".done-button")!);
+
+ expect(container.querySelector(".edit-players-dialog")).toBeNull();
+ });
+});
+
+describe("the window for editing players on a touch screen", () => {
+ const originalMatchMedia = window.matchMedia;
+ beforeEach(() => {
+ window.matchMedia = ((query: string) => ({
+ matches: query.includes("pointer: coarse"),
+ media: query,
+ addEventListener: () => {},
+ removeEventListener: () => {},
+ })) as unknown as typeof window.matchMedia;
+ });
+ afterEach(() => {
+ window.matchMedia = originalMatchMedia;
+ });
+
+ const nameBoxes = (container: HTMLElement) =>
+ Array.from(container.querySelectorAll(".player-name-input"));
+
+ it("puts the cursor in a name as it opens, so that the keyboard is up", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+
+ await user.click(container.querySelector(".edit-players-button")!);
+
+ const [box] = nameBoxes(container);
+ expect(document.activeElement).toBe(box);
+ expect(box!.selectionStart).toBe(box!.selectionEnd); // Opened by a tap, so nothing is selected
+ });
+
+ it("keeps the cursor in the name when something else in the window is pressed", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+
+ const title = container.querySelector(".edit-players-title")!;
+ const notCancelled = fireEvent.mouseDown(title); // False when the press is stopped taking the focus
+
+ expect(notCancelled).toBe(false);
+ expect(document.activeElement).toBe(nameBoxes(container)[0]);
+ });
+
+ it("keeps the cursor in the name when the page behind the window is pressed", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+
+ const notCancelled = fireEvent.mouseDown(container.querySelector(".edit-players-backdrop")!);
+
+ expect(notCancelled).toBe(false);
+ expect(document.activeElement).toBe(nameBoxes(container)[0]);
+ });
+
+ it("goes on to the next name with Enter, rather than putting the keyboard away", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+ await user.click(container.querySelector(".add-player-button")!);
+ const [first, second] = nameBoxes(container);
+ first!.focus();
+
+ await user.keyboard("{Enter}");
+
+ expect(document.activeElement).toBe(second);
+ });
+
+ it("puts the cursor back in a name after the one that had it is deleted", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(container.querySelector(".edit-players-button")!);
+ await user.click(container.querySelector(".add-player-button")!); // The new name has the focus
+
+ await user.click(container.querySelectorAll(".delete-button")[1]!);
+
+ await waitFor(() => expect(document.activeElement).toBe(nameBoxes(container)[0]));
+ });
+});
+
+describe("the tabs on a screen that is taller than it is wide", () => {
+ const originalMatchMedia = window.matchMedia;
+ beforeEach(() => {
+ window.matchMedia = ((query: string) => ({
+ matches: query.includes("max-aspect-ratio"),
+ media: query,
+ addEventListener: () => {},
+ removeEventListener: () => {},
+ })) as unknown as typeof window.matchMedia;
+ });
+ afterEach(() => {
+ window.matchMedia = originalMatchMedia;
+ });
+
+ it("has no button for expanding the player list", () => {
+ renderApp("/play/");
+ expect(screen.queryByRole("button", { name: /player list/i })).toBeNull();
+ });
+
+ it("expands the list, and drops the tab, when the tab that is showing is pressed", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ const keypad = screen.getByRole("tab", { name: "Keypad" });
+ expect(keypad.getAttribute("aria-selected")).toBe("true");
+
+ await user.click(keypad);
+
+ expect(container.querySelector(".list-expanded")).not.toBeNull();
+ expect(keypad.getAttribute("aria-selected")).toBe("false");
+ expect(
+ screen.getAllByRole("tab").every((tab) => tab.getAttribute("aria-selected") === "false"),
+ ).toBe(true);
+ });
+
+ it("shows the total scores in the list on its own, as it does after the plot or the table", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ const heading = () => container.querySelector(".round-label")!.textContent;
+ expect(heading()).toMatch(/^Round /);
+
+ await user.click(screen.getByRole("tab", { name: "Keypad" })); // Pressed while showing: none selected
+
+ expect(heading()).toBe("Total Scores");
+
+ await user.click(screen.getByRole("tab", { name: "Keypad" }));
+
+ expect(heading()).toMatch(/^Round /);
+ });
+
+ it("does not take scores from the keyboard while the list is on its own", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(screen.getByRole("tab", { name: "Keypad" }));
+
+ fireEvent.keyDown(window, { key: "7" });
+
+ expect(container.querySelector(".score-value")!.textContent).toBe("0");
+ });
+
+ it("brings the tab back, and shrinks the list, when a tab is pressed after that", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ await user.click(screen.getByRole("tab", { name: "Keypad" }));
+
+ await user.click(screen.getByRole("tab", { name: "Plot" }));
+
+ expect(container.querySelector(".list-expanded")).toBeNull();
+ expect(screen.getByRole("tab", { name: "Plot" }).getAttribute("aria-selected")).toBe("true");
+ });
+
+ it("does the same for the plot and the table", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ for (const name of ["Plot", "Table"]) {
+ await user.click(screen.getByRole("tab", { name }));
+ expect(container.querySelector(".list-expanded")).toBeNull();
+ await user.click(screen.getByRole("tab", { name }));
+ expect(container.querySelector(".list-expanded")).not.toBeNull();
+ }
+ });
+
+ it("gives the table the room that the player list would have had", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+ expect(container.querySelector(".table-showing")).toBeNull();
+
+ await user.click(screen.getByRole("tab", { name: "Table" }));
+ expect(container.querySelector(".table-showing")).not.toBeNull();
+
+ await user.click(screen.getByRole("tab", { name: "Plot" }));
+ expect(container.querySelector(".table-showing")).toBeNull();
+ });
+});
+
+describe("pressing the tab that is showing on a wide screen", () => {
+ it("does nothing, as the list is beside the panel already", async () => {
+ const user = userEvent.setup();
+ const { container } = renderApp("/play/");
+
+ await user.click(screen.getByRole("tab", { name: "Keypad" }));
+
+ expect(container.querySelector(".list-expanded")).toBeNull();
+ expect(screen.getByRole("tab", { name: "Keypad" }).getAttribute("aria-selected")).toBe("true");
});
});
@@ -1473,10 +1713,10 @@ describe("keypad caption", () => {
it("follows a player being renamed", async () => {
const user = userEvent.setup();
const { container } = renderApp("/play/");
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.clear(container.querySelector(".player-name-input")!);
await user.type(container.querySelector(".player-name-input")!, "Ada");
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".done-button")!);
expect(caption(container)).toBe("Ada · Round 1");
});
@@ -1484,37 +1724,39 @@ describe("keypad caption", () => {
it("copes with a player whose name has been cleared", async () => {
const user = userEvent.setup();
const { container } = renderApp("/play/");
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.clear(container.querySelector(".player-name-input")!);
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".done-button")!);
expect(caption(container)).toBe("Player · Round 1");
});
- it("says what to do when the player list is empty, in and out of edit mode", async () => {
+ it("says what to do when there are no players, in the list and in the window for editing them", async () => {
const user = userEvent.setup();
const { container } = renderApp("/play/");
await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".delete-button")!);
- expect(screen.getByText("No players yet")).toBeTruthy();
- const hint = container.querySelector(".player-list-empty-hint")!;
+ expect(screen.getAllByText("No players yet")).toHaveLength(2);
+ const hint = container.querySelector(".edit-players-empty-hint")!;
expect(hint.textContent).toBe("Press Add player to add one");
- expect(hint.querySelector(".player-list-empty-button")!.textContent).toBe("Add player");
+ expect(hint.querySelector(".edit-players-empty-button")!.textContent).toBe("Add player");
await user.click(container.querySelector(".done-button")!);
- expect(hint.textContent).toBe("Press Edit players to add some");
- expect(hint.querySelector(".player-list-empty-button")!.textContent).toBe("Edit players");
+ const listHint = container.querySelector(".player-list-empty-hint")!;
+ expect(listHint.textContent).toBe("Press Edit players to add some");
+ expect(listHint.querySelector(".player-list-empty-button")!.textContent).toBe("Edit players");
await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".add-player-button")!);
expect(container.querySelector(".player-list-empty")).toBeNull();
+ expect(container.querySelector(".edit-players-empty")).toBeNull();
});
it("copes with there being no players", async () => {
const user = userEvent.setup();
const { container } = renderApp("/play/");
- await user.click(container.querySelector(".done-button, .edit-players-button")!);
+ await user.click(container.querySelector(".edit-players-button")!);
await user.click(container.querySelector(".delete-button")!);
expect(caption(container)).toBe("Round 1");
@@ -1588,13 +1830,14 @@ describe("labelled buttons", () => {
expect(screen.getByRole("button", { name: "Next round" })).toBeTruthy();
});
- it("say what the edit button does now", async () => {
+ it("name the window that the edit button opens, with a Done button to close it", async () => {
const user = userEvent.setup();
renderApp("/play/");
await user.click(screen.getByRole("button", { name: "Edit players" }));
- expect(screen.getByRole("button", { name: "Done" })).toBeTruthy();
- expect(screen.queryByRole("button", { name: "Edit players" })).toBeNull();
+ expect(screen.getByRole("dialog", { name: "Edit Players" })).toBeTruthy();
+ await user.click(screen.getByRole("button", { name: "Done" }));
+ expect(screen.queryByRole("dialog")).toBeNull();
});
it("name the add player button, which only exists for assistive technology in edit mode", async () => {
@@ -1616,10 +1859,6 @@ describe("labelled buttons", () => {
await user.click(screen.getByRole("tab", { name: "Plot" })); // Not showing a round
expect(screen.queryByRole("button", { name: "Next round" })).toBeNull();
expect(screen.queryByRole("button", { name: "Previous round" })).toBeNull();
-
- await user.click(screen.getByRole("tab", { name: "Keypad" }));
- await user.click(screen.getByRole("button", { name: "Edit players" })); // Editing, so no rounds
- expect(screen.queryByRole("button", { name: "Next round" })).toBeNull();
});
});
});
@@ -1627,7 +1866,6 @@ describe("labelled buttons", () => {
describe("focus after pressing a button", () => {
// The browser draws a focus ring around a focused button as soon as a key (even Shift, for
// scrolling sideways) is pressed, so a button that was only clicked must not stay focused.
- const focusedLabel = () => document.activeElement?.getAttribute("aria-label");
it("is let go of when a button is clicked with the mouse", async () => {
const user = userEvent.setup();
@@ -1651,7 +1889,7 @@ describe("focus after pressing a button", () => {
];
for (const find of buttons) {
await user.click(find());
- expect(document.activeElement).toBe(document.body);
+ expect(document.activeElement instanceof HTMLButtonElement).toBe(false);
}
});
@@ -1695,7 +1933,6 @@ describe("focus after pressing a button", () => {
await user.click(name);
expect(document.activeElement).toBe(name);
- expect(focusedLabel()).toBeNull();
});
});
@@ -1998,15 +2235,15 @@ describe("letting go of a pinned player by pressing elsewhere", () => {
const { container } = renderApp("/play/");
await user.click(screen.getByRole("tab", { name: "Plot" }));
- await user.click(container.querySelector(".game-name-label")!);
+ await user.click(container.querySelector(".plot-area")!);
expect(container.querySelector(".player.pinned")).toBeNull();
});
});
-describe("flashing the row of a player whose score was updated", () => {
+describe("bouncing the score of a player whose score was updated", () => {
const flashing = (container: HTMLElement) =>
- Array.from(container.querySelectorAll(".player")).map(
+ Array.from(container.querySelectorAll(".player .score")).map(
(row) => row.classList.contains("flash-a") || row.classList.contains("flash-b"),
);
const enterScore = (score: string) => {
@@ -2046,7 +2283,7 @@ describe("flashing the row of a player whose score was updated", () => {
it("starts the flash over for a player who scores again, with a different animation", async () => {
const { container } = await twoPlayers();
- const first = () => container.querySelectorAll(".player")[0]!;
+ const first = () => container.querySelectorAll(".player .score")[0]!;
enterScore("5"); // Player 1
expect(first().classList.contains("flash-a")).toBe(true);
@@ -2088,7 +2325,7 @@ describe("flashing the row of a player whose score was updated", () => {
await user.keyboard("9{Enter}");
expect(before).toEqual([true, true]);
- const rows = container.querySelectorAll(".player");
+ const rows = container.querySelectorAll(".player .score");
expect(rows[1]!.classList.contains("flash-b")).toBe(true); // The second time for Player 2
expect(rows[0]!.classList.contains("flash-a")).toBe(true); // Still the first time for Player 1
});
@@ -2096,7 +2333,7 @@ describe("flashing the row of a player whose score was updated", () => {
it("does not when the score is left as it was, or cancelled, or is not a number", async () => {
const { user, container } = await onTheTable();
const classes = () =>
- Array.from(container.querySelectorAll(".player")).map((row) => row.className);
+ Array.from(container.querySelectorAll(".player .score")).map((row) => row.className);
const before = classes();
await user.click(scoreButton(container, 0));
@@ -2131,7 +2368,7 @@ describe("flashing the row of a player whose score was updated", () => {
it("does not flash when a player is selected by pressing them", async () => {
const { user, container } = await twoPlayers();
- await user.click(container.querySelectorAll(".player")[1]!);
+ await user.click(container.querySelectorAll(".player .score")[1]!);
expect(flashing(container)).toEqual([false, false]);
});
@@ -2159,7 +2396,7 @@ describe("flashing the row of a player whose score was updated", () => {
await user.click(screen.getByRole("button", { name: "Done" }));
expect(() => enterScore("5")).not.toThrow();
- expect(container.querySelectorAll(".player")).toHaveLength(0);
+ expect(container.querySelectorAll(".player .score")).toHaveLength(0);
});
});
});
diff --git a/web/src/components/FittedText.tsx b/web/src/components/FittedText.tsx
deleted file mode 100644
index 00b94bd..0000000
--- a/web/src/components/FittedText.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { useLayoutEffect, useRef } from "react";
-
-/** The smallest the text is made, below which a long name is cut off with "…" instead */
-const MIN_FONT_SIZE_PX = 13;
-
-/**
- * Text that gets smaller when it would otherwise be too big for the box it is in, rather than being
- * cut off. It is as big as the stylesheet makes it unless that doesn't fit.
- *
- * The box is the text's own element, which the stylesheet has to give a size to fit (by letting it
- * shrink, and hiding what overflows) rather than one that grows to suit the text.
- */
-export function FittedText({ text, className }: { text: string; className?: string }) {
- const ref = useRef(null);
-
- useLayoutEffect(() => {
- const element = ref.current;
- if (!element) return;
- const el: HTMLSpanElement = element;
-
- // A couple of pixels of leeway on the height, as the lines of text are rounded and the descenders
- // of the last one can hang a little past the box. A whole extra line is a lot more than that.
- const overflows = () =>
- el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 3;
-
- function fit() {
- el.style.fontSize = ""; // Back to the size that the stylesheet gives it, to start from
- let size = parseFloat(getComputedStyle(el).fontSize);
- while (size > MIN_FONT_SIZE_PX && overflows()) {
- size -= 1;
- el.style.fontSize = `${size}px`;
- }
- }
-
- fit();
- // The size of the text depends on the font, which may not have loaded yet
- let cancelled = false;
- void document.fonts?.ready.then(() => {
- if (!cancelled) fit();
- });
- // The space changes with the window, and when the layout changes. Its parent is watched, as
- // the text itself is not what decides how big the space is.
- const observer = new ResizeObserver(fit);
- if (el.parentElement) observer.observe(el.parentElement);
- return () => {
- cancelled = true;
- observer.disconnect();
- };
- }, [text]);
-
- return (
-
- {text}
-
- );
-}
diff --git a/web/src/components/game-play-page/GamePlayPage.scss b/web/src/components/game-play-page/GamePlayPage.scss
index 1d731de..16bb888 100644
--- a/web/src/components/game-play-page/GamePlayPage.scss
+++ b/web/src/components/game-play-page/GamePlayPage.scss
@@ -1,3 +1,4 @@
+@use "sass:color";
@use "../../Colors.scss" as *;
@use "../../Breakpoints.scss" as *;
@@ -7,6 +8,16 @@ $left-width: clamp(420px, 38vw, 500px);
// How much the tabs curve where they meet the main panel
$tab-flare: 8px;
+// The column of tabs beside the player list, which the header stops short of
+$tabs-width: 90px;
+
+// The sizes of what is stacked, which the size of the panel is worked out from (see .content-inner)
+$stacked-header-height: 64px;
+$stacked-tabs-height: 56px;
+$stacked-gap: 10px;
+
+$done-color: color.mix($light-elements, $gray-3, 75%); // The same as the Enter key
+
.game-play-background {
display: flex;
align-items: center;
@@ -26,29 +37,26 @@ $tab-flare: 8px;
.top-left-section {
flex: none; // Keep its height, however long the player list gets
- width: 100%;
- height: 100px;
+ width: calc(100% - $tabs-width); // To end where the player list does, not where the tabs do
+ height: 45px;
display: flex;
gap: 10px;
- // Just the Home button, as tall as the header, which is as tall as the outline of the game name
+ // Home, the button for editing the players (or finishing), then fullscreen, side by side
.top-buttons-section {
- width: 80px;
+ flex: 1;
+ min-width: 0;
display: flex;
- flex-direction: column;
gap: 10px;
button {
- flex: 1;
display: flex;
align-items: center;
- justify-content: flex-start; // Over towards the edge of the screen, which is where back is
+ justify-content: center;
background-color: $gray-1;
border: 1px solid $gray-4;
- border-left: 0;
- border-top-right-radius: 16px;
- border-bottom-right-radius: 16px;
- color: rgba($light-elements, 0.55); // Both icons, which are quiet, as it is not used much
+ border-radius: 16px;
+ color: rgba($light-elements, 0.55); // The icons are quiet, as they are not used much
cursor: pointer;
&:hover {
@@ -68,93 +76,54 @@ $tab-flare: 8px;
}
}
- // Fullscreen, under Home. Smaller icon and centered, as it is not about going back.
+ // Over towards the edge of the screen, which is where back is
+ .button-home {
+ flex: none;
+ width: 80px;
+ justify-content: flex-start;
+ border-left: 0;
+ border-top-left-radius: 0;
+ border-bottom-left-radius: 0;
+ }
+
+ // Smaller icon, as it is not about going back
.button-fullscreen {
- justify-content: center;
+ flex: none;
+ width: 56px;
span {
font-size: 28px;
}
}
- }
-
- .game-name-section {
- position: relative;
- flex: 1;
- min-width: 0;
- margin-right: 10px;
- background-color: $gray-1;
- border: 1px solid $gray-4;
- border-radius: 16px;
- display: flex;
- align-items: center;
- justify-content: center;
-
- // While the name is being edited, the panel stays the shade that it was when it was pointed
- // at to start, so that there is no change of color as the text box replaces the name
- &.editing {
- background-color: $gray-2;
- }
- // The name, which is pressed to rename the game
- .game-name-label {
- position: relative;
- width: 100%;
- height: 100%;
+ .edit-players-button,
+ .done-button {
+ flex: 1;
min-width: 0;
- padding: 0 16px 3px;
- display: flex;
- align-items: center;
- justify-content: center;
- background: none;
- border: 0;
- border-radius: 15px;
- color: $light-elements;
- cursor: pointer;
+ gap: 8px;
font-family: inherit;
- font-size: 22pt;
- font-weight: bold;
- touch-action: manipulation;
- -webkit-tap-highlight-color: transparent;
- transition: background-color 60ms ease;
-
- .game-name-text {
- min-width: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
-
- @media (hover: hover) {
- &:hover {
- background-color: $gray-2;
- }
- }
+ font-size: 15px;
+ font-weight: 600;
+ white-space: nowrap;
- // No lighter shade for pressing: the name turns into a text box as soon as it is pressed,
- // and it has to carry on looking the same through that, or it flickers
- &:focus-visible {
- outline: 2px solid $light-elements;
- outline-offset: -4px;
+ span {
+ font-size: 22px;
}
}
- .game-name-input {
- background-color: $gray-3;
- width: calc(100% - 20px);
- min-width: 0; // Don't let the input's intrinsic width resize the layout
- padding: 0 8px 3px;
- border: 1px solid $gray-5;
- border-radius: 8px;
- color: $light-elements;
- font-family: inherit;
- font-size: 22pt;
- font-weight: bold;
- text-align: center;
+ // The way out of editing, so it is as prominent as the Enter key of the keypad
+ .done-button {
+ background-color: $done-color;
+ border-color: $done-color;
+ color: $background;
+
+ &:hover {
+ background-color: $done-color;
+ filter: brightness(0.94);
+ }
- &:focus {
- outline: none;
- border-color: $light-elements;
+ &:active {
+ filter: brightness(0.85);
}
}
}
@@ -173,23 +142,17 @@ $tab-flare: 8px;
display: flex; // The round buttons and the add player button stay put, the list scrolls
flex-direction: column;
overflow: hidden;
- position: relative; // For the button that expands it, in the corner
background-color: $gray-1;
border: 1px solid $gray-4;
border-left: 0;
border-top-right-radius: 16px;
border-bottom-right-radius: 16px;
-
- // Only for the stacked layout, where there is room below to grow into
- .expand-list-button {
- display: none;
- }
}
// The tabs for the keypad, the plot and the table. Side by side, they hang off the left edge
// of the content, and the selected one joins up with it.
.buttons-section {
- flex: 0 0 90px;
+ flex: 0 0 $tabs-width;
height: 90%;
display: flex;
flex-direction: column;
@@ -229,7 +192,7 @@ $tab-flare: 8px;
// corner. The other tabs have square corners where they meet the panel's line. Each curve is
// a small square, filled where the corner is, and drawn with the same line as the outline.
&.selected {
- width: 73px;
+ width: 76px;
margin-right: -1px;
z-index: 2;
@@ -270,15 +233,59 @@ $tab-flare: 8px;
}
}
- &:hover:not(.selected) {
- background-color: $gray-3;
+ // Only for a mouse. On a touchscreen :hover stays on what was tapped, which for the tab that
+ // was just pressed to drop it would leave it looking like it is still being pointed at.
+ @media (hover: hover) {
+ &:hover:not(.selected) {
+ background-color: $gray-3;
+ }
}
}
}
}
}
+// Fills the panel, whatever it holds. When the panel changes to another, either the new one slides up
+// over the one that it replaces, or the old one drops away to uncover the new one, which are why each
+// has a background of its own.
+.content-inner {
+ position: absolute;
+ inset: 0;
+ z-index: 1;
+ background-color: $gray-1;
+
+ &.entering {
+ z-index: 2;
+ animation: content-slide-up 250ms ease-out;
+ }
+
+ &.dropping {
+ z-index: 2;
+ animation: content-drop-down 250ms ease-in forwards;
+ }
+}
+
+@keyframes content-drop-down {
+ to {
+ transform: translateY(100%);
+ }
+}
+
+@keyframes content-slide-up {
+ from {
+ transform: translateY(100%);
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .content-inner.entering,
+ .content-inner.dropping {
+ animation: none;
+ }
+}
+
.content-section {
+ position: relative;
flex: 1;
min-width: 0;
height: 90%;
@@ -287,6 +294,9 @@ $tab-flare: 8px;
border-right: none;
border-top-left-radius: 16px;
border-bottom-left-radius: 16px;
+ // What is in it is cut off at its rounded corners (inside its border), rather than being drawn over
+ // them, and a tab sliding over another is not to be seen outside it
+ overflow: hidden;
}
// On portrait screens everything is stacked: the header, the list, the content, then the tabs
@@ -294,11 +304,15 @@ $tab-flare: 8px;
.game-play-background {
display: grid;
grid-template-columns: minmax(0, 1fr);
- grid-template-rows: auto minmax(160px, 36%) minmax(0, 1fr) auto;
- gap: 10px;
+ grid-template-rows: auto 36fr 64fr auto;
+ transition:
+ transform 150ms ease-out,
+ grid-template-rows 250ms ease;
+ gap: $stacked-gap;
// More room above and below than at the sides, as a phone's screen has rounded corners
padding: 28px 12px;
align-items: stretch;
+ container-type: size; // For working out how tall the panel will be, see .content-inner
}
// The columns are only there to arrange things side by side. Take them out of the way, so that
@@ -310,45 +324,28 @@ $tab-flare: 8px;
.left-section .top-left-section {
grid-row: 1;
- height: 64px;
+ width: 100%; // There are no tabs beside the list here
+ height: $stacked-header-height;
.top-buttons-section {
- width: auto;
- flex-direction: row;
-
- button {
- flex: none;
- width: 64px;
+ .button-home {
+ width: 76px;
+ justify-content: center;
border-left: 1px solid $gray-4;
border-radius: 16px;
}
.button-fullscreen {
- width: 48px;
- }
- }
-
- .game-name-section {
- margin-right: 0;
-
- .game-name-label,
- .game-name-input {
- font-size: 18pt;
+ width: 60px;
}
- // The name can take two lines, so that more of a long one fits on a narrow screen
- .game-name-label {
- padding: 0 12px;
- }
+ // There is room for it to be bigger
+ .edit-players-button {
+ font-size: 17px;
- .game-name-label .game-name-text {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- font-size: 16pt;
- line-height: 1.15;
- text-align: center;
- white-space: normal;
+ span {
+ font-size: 24px;
+ }
}
}
}
@@ -363,7 +360,7 @@ $tab-flare: 8px;
button {
flex: 1;
width: auto;
- height: 56px;
+ height: $stacked-tabs-height;
margin-right: 0;
border: 1px solid $gray-4;
border-radius: 16px;
@@ -405,66 +402,6 @@ $tab-flare: 8px;
grid-row: 2;
border-left: 1px solid $gray-4;
border-radius: 16px;
-
- // Small, in the lower right, and over the list rather than taking room from it. Styled like the
- // Edit players button: quiet until it is pointed at.
- .expand-list-button {
- position: absolute;
- right: 10px;
- bottom: 10px;
- z-index: 1;
- width: 44px;
- height: 44px;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: $gray-1;
- border: 1px solid $gray-3;
- border-radius: 12px;
- color: rgba($light-elements, 0.45);
- cursor: pointer;
- touch-action: manipulation;
- -webkit-tap-highlight-color: transparent;
- transition:
- transform 60ms ease,
- background-color 60ms ease,
- border-color 60ms ease,
- color 60ms ease;
-
- @media (hover: hover) {
- &:hover:not(:active) {
- background-color: $gray-2;
- border-color: $gray-5;
- color: $light-elements;
- }
- }
-
- &:active {
- transform: scale(0.94);
- background-color: $gray-4;
- }
-
- &:focus-visible {
- outline: 2px solid $light-elements;
- outline-offset: 2px;
- }
-
- // Two chevrons pointing down, overlapping so that they read as one icon
- .double-chevron {
- display: flex;
- flex-direction: column;
- align-items: center;
-
- .material-symbols-outlined {
- font-size: 22px;
- transform: rotate(90deg);
-
- + .material-symbols-outlined {
- margin-top: -13px;
- }
- }
- }
- }
}
}
@@ -473,20 +410,78 @@ $tab-flare: 8px;
height: auto;
border-right: 1px solid $gray-4;
border-radius: 16px;
+ overflow: hidden; // So that its contents do not show outside it while it changes size
}
- // The list takes the main panel's place, which stays where it is but out of sight
- .list-expanded {
+ // The panel changes size as the list gives it room and takes it back, and what is in it does not:
+ // it is the size that the panel is going to be, and the panel shows as much of it as it has room
+ // for. It is kept to the bottom of the panel, which is the edge that stays where it is (the top is
+ // what moves), so what is in it stays still on the screen as the panel grows or shrinks around it,
+ // whether it is being covered by another tab, or by the list, or is uncovered. That size is worked out from the room that there is
+ // (the height of the page, less what is not shared out between them), as the panel takes 64
+ // hundredths of it when it is beside the list, or all of it (and the gap above) for the table.
+ $shared-room: calc(100cqh - $stacked-header-height - $stacked-tabs-height - 3 * $stacked-gap);
+ .content-inner {
+ top: auto;
+ bottom: 0;
+ height: calc($shared-room * 0.64 - 2px); // Less the panel's border
+
+ &.is-table {
+ height: calc($shared-room + $stacked-gap - 2px);
+ }
+ }
+
+ // The list and the panel share the room between them, as fractions of a hundred that add up to the
+ // same each time (so that nothing is lost in between), and give it to each other by changing
+ // them: all of it to the table, which has the players in its own headings, or all of it to the
+ // list, when it is expanded. Changing them is animated, here and by the margins below. Whichever
+ // has no room left is hidden once it has finished going (which is why that is delayed).
+ .content-section,
+ .left-section .bottom-left-section .player-list-section {
+ min-height: 0; // To be able to go all the way down to nothing
+ transition: margin 250ms ease;
+ }
+
+ .table-showing:not(.list-expanded) {
+ grid-template-rows: auto 0fr 100fr auto;
+
+ .content-section {
+ margin-top: -10px; // The gap that the list's row has above it is not wanted either
+ }
+
.left-section .bottom-left-section .player-list-section {
- grid-row: 2 / 4;
+ visibility: hidden;
+ transition:
+ margin 250ms ease,
+ visibility 0s linear 250ms;
+ }
+ }
- .expand-list-button .double-chevron {
- transform: rotate(180deg); // Pointing up: shrink
- }
+ .list-expanded {
+ grid-template-rows: auto 100fr 0fr auto;
+
+ .left-section .bottom-left-section .player-list-section {
+ margin-bottom: -10px; // And the gap that the panel's row has below it
}
.content-section {
- display: none;
+ visibility: hidden;
+ transition:
+ margin 250ms ease,
+ visibility 0s linear 250ms;
+ }
+ }
+
+ // The list is not to grow a scroll bar as it shrinks, for the moment that it has too little room
+ .resizing .player-list {
+ overflow-y: hidden;
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ .game-play-background,
+ .content-section,
+ .left-section .bottom-left-section .player-list-section {
+ transition: none !important;
}
}
}
@@ -499,13 +494,6 @@ $tab-flare: 8px;
}
.left-section .top-left-section {
- height: 76px;
-
- .game-name-section {
- .game-name-label,
- .game-name-input {
- font-size: 18pt;
- }
- }
+ height: 33px;
}
}
diff --git a/web/src/components/game-play-page/GamePlayPage.tsx b/web/src/components/game-play-page/GamePlayPage.tsx
index 76761e1..a19f674 100644
--- a/web/src/components/game-play-page/GamePlayPage.tsx
+++ b/web/src/components/game-play-page/GamePlayPage.tsx
@@ -3,9 +3,10 @@ import clsx from "clsx";
import { useCallback, useEffect, useRef, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { useGame } from "@/GameContext";
-import { FittedText } from "@/components/FittedText";
+import { useToast } from "@/ToastContext";
import { lastRound } from "@/utils/Scores";
import { runWithTransition, usePageAppeared } from "@/viewTransition";
+import { EditPlayersDialog } from "./edit-players-dialog/EditPlayersDialog";
import { EnterScoresComponent } from "./enter-scores-component/EnterScoresComponent";
import { PlayerListComponent } from "./player-list-component/PlayerListComponent";
import { PlotScoresComponent } from "./plot-scores-component/PlotScoresComponent";
@@ -13,6 +14,20 @@ import { ScoreTableComponent } from "./score-table-component/ScoreTableComponent
import { useKeepAboveKeyboard } from "@/useKeepAboveKeyboard";
import { FullscreenButton } from "@/components/FullscreenButton";
+/** How long a tab takes to slide up over the one before it, or to drop away from in front of one */
+const SLIDE_MS = 250;
+
+/** Whether things are to be moved about, rather than just changed */
+function motionAllowed(): boolean {
+ return (
+ typeof window.matchMedia === "function" &&
+ !window.matchMedia("(prefers-reduced-motion: reduce)").matches
+ );
+}
+
+/** How long the player list takes to change size (a little longer than the stylesheet says) */
+const RESIZE_MS = 300;
+
type Content = "keypad" | "plot" | "table";
const contentButtons: { content: Content; icon: string; label: string }[] = [
@@ -24,16 +39,51 @@ const contentButtons: { content: Content; icon: string; label: string }[] = [
export function GamePlayPage() {
const navigate = useNavigate();
usePageAppeared();
- // "Start New Game" opens this page already in edit mode so the players can be set up
- const startInEditMode = (useLocation().state as { newGame?: boolean } | null)?.newGame === true;
+ // "Start New Game" opens this page with the window for editing the players already open, so that
+ // they can be set up
+ const location = useLocation();
+ const startInEditMode = (location.state as { newGame?: boolean } | null)?.newGame === true;
+ // Whether the window opened by itself, for a new game. Kept from then until it is closed, as the
+ // address still says it is a new game for as long as the page is there.
+ const [forNewGame, setForNewGame] = useState(startInEditMode);
+ // And not for as long as the history says so: going back to this page, or reloading it, is not a
+ // new game
+ useEffect(() => {
+ if (startInEditMode) navigate(location.pathname, { replace: true, state: null });
+ }, [startInEditMode, navigate, location.pathname]);
const { game, updateGame } = useGame();
+ const { dismissAll } = useToast();
useKeepAboveKeyboard();
+ // What the panel holds. With the list on its own (below), it still holds what it did, out of sight.
const [currentContent, setCurrentContent] = useState("keypad");
// On a stacked layout, the list can grow down over the space of the main panel
const [listExpanded, setListExpanded] = useState(false);
+ // The tab that is selected, which is none while the list is on its own. That is a state of its own,
+ // before the first tab: it is not the tab that the panel was holding, with the list over it.
+ const tab: Content | null = listExpanded ? null : currentContent;
const [selectedPlayerIdState, setSelectedPlayerId] = useState("");
// Continuing a game picks up at its latest round; a new game starts at round 1
const [currentRound, setCurrentRound] = useState(() => Math.max(1, lastRound(game)));
+ // How the panel is changing, for as long as that takes. The list on its own counts as the first of
+ // the tabs, before the keypad. Going to a tab that is further along, the new one slides up ("up",
+ // over the one it replaces, or "in", from there being none). Going to one before, the old one
+ // drops away ("drop", which uncovers the one it replaced, or "out", which uncovers the list).
+ const [slide, setSlide] = useState<{
+ leaving: Content | null;
+ kind: "up" | "drop" | "in" | "out";
+ } | null>(null);
+ const leavingContent = slide?.leaving ?? null;
+ const slideTimer = useRef>(undefined);
+ useEffect(() => () => clearTimeout(slideTimer.current), []);
+ function startSlide(next: NonNullable) {
+ setSlide(next);
+ clearTimeout(slideTimer.current);
+ slideTimer.current = setTimeout(() => setSlide(null), SLIDE_MS + 50);
+ }
+ const [resizing, setResizing] = useState(false);
+ const resizeTimer = useRef>(undefined);
+ useEffect(() => () => clearTimeout(resizeTimer.current), []);
+ // Whether the window for editing the players is open
const [editing, setEditing] = useState(startInEditMode);
// The plot emphasizes the line of the player the mouse is over in the player list, or failing
// that, of the one that was tapped (which is the only way to do it without a mouse)
@@ -41,13 +91,6 @@ export function GamePlayPage() {
const [pinnedPlayerIdState, setPinnedPlayerId] = useState("");
// How many times each player's row has been made to flash, which the row restarts its flash by
const [flashCounts, setFlashCounts] = useState>({});
- // The game name is edited on its own, by pressing it, whether or not the players are being edited.
- // A new game starts with its name being edited, ready to be typed over.
- const [editingName, setEditingName] = useState(startInEditMode);
- const nameBeforeEditing = useRef(game.name);
- // Whether the name should be selected when its text box appears, which is only the first time
- const selectGameName = useRef(startInEditMode);
- const gameNameRef = useRef(null);
const playerListRef = useRef(null);
// Fall back to the first player if the selected player doesn't exist (e.g. it was deleted)
@@ -56,7 +99,7 @@ export function GamePlayPage() {
? selectedPlayerIdState
: firstPlayerId;
- const pinnedPlayerId = currentContent === "plot" && !editing ? pinnedPlayerIdState : "";
+ const pinnedPlayerId = tab === "plot" && !editing ? pinnedPlayerIdState : "";
const highlightedPlayerId = hoveredPlayerId || pinnedPlayerId;
// What the keypad says the score being typed is for
@@ -66,54 +109,14 @@ export function GamePlayPage() {
? `${selectedPlayer.playerName.trim() || "Player"} · ${roundName}`
: roundName;
- // When leaving edit mode, go back to the first player
+ // However the window is closed, go back to the first player. Deletions were meant, so there is no
+ // more need to offer to undo them.
const exitEditMode = useCallback(() => {
+ dismissAll();
setEditing(false);
+ setForNewGame(false);
setSelectedPlayerId(firstPlayerId);
- }, [firstPlayerId]);
-
- // Exit edit mode if user clicks anywhere other than the game name or the player list (which has
- // the buttons for starting and finishing editing in it)
- useEffect(() => {
- if (!editing) return;
-
- function onPointerDown(event: PointerEvent) {
- const target = event.target as Node;
- // Pressing a toast (like Undo, after deleting a player) is part of editing, not leaving it
- if (target instanceof Element && target.closest(".toasts")) return;
- // Likewise the color picker, which is in the body, not the player list, but is part of editing
- if (target instanceof Element && target.closest(".color-select-background")) return;
- if (!gameNameRef.current?.contains(target) && !playerListRef.current?.contains(target)) {
- exitEditMode();
- }
- }
-
- document.addEventListener("pointerdown", onPointerDown);
- return () => document.removeEventListener("pointerdown", onPointerDown);
- }, [editing, exitEditMode]);
-
- // Pressing Enter while editing, with no name being edited, means the editing is done
- useEffect(() => {
- if (!editing) return;
-
- function onKeyDown(event: KeyboardEvent) {
- if (event.key !== "Enter" || event.repeat) return; // Not the Enter of a key held down
- if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return;
-
- // Where the key was pressed, not where the focus is now: Enter in a name box takes the focus
- // out of it, and that Enter has done its job by doing that. On a button, Enter presses it.
- const target = event.target;
- if (target instanceof Element && target.closest("input, textarea, select, button")) return;
-
- // The color picker has its own idea of what is going on
- if (document.querySelector(".color-select-background")) return;
-
- exitEditMode();
- }
-
- window.addEventListener("keydown", onKeyDown);
- return () => window.removeEventListener("keydown", onKeyDown);
- }, [editing, exitEditMode]);
+ }, [dismissAll, firstPlayerId]);
// Let go of a pinned player when pressing anywhere, other than on a button (a tab, say, which can
// decide for itself whether to let go) or a player, which pins or unpins them as it is pressed
@@ -146,11 +149,38 @@ export function GamePlayPage() {
// Pressing a player selects them for entering scores, and on the plot, picks out their line
function onPlayerPressed(playerId: string) {
setSelectedPlayerId(playerId);
- if (currentContent === "plot" && !editing) {
+ if (tab === "plot" && !editing) {
setPinnedPlayerId(pinnedPlayerId === playerId ? "" : playerId);
}
}
+ // The list changes size with the tabs (when stacked), which takes a moment, and for that moment it
+ // is not to have a scroll bar come and go
+ function noteResize() {
+ setResizing(true);
+ clearTimeout(resizeTimer.current);
+ resizeTimer.current = setTimeout(() => setResizing(false), RESIZE_MS);
+ }
+
+ // Where the tabs are along the bottom, with the list above the panel rather than beside it
+ function isStackedLayout() {
+ return window.matchMedia?.("(max-aspect-ratio: 1 / 1)").matches ?? false;
+ }
+
+ // Pressing the tab that is showing, when stacked, drops it and lets the list have its panel's place
+ function pressTab(content: Content) {
+ noteResize();
+ if (content === tab && isStackedLayout()) {
+ setListExpanded(true);
+ // Showing the totals, as for the plot and the table
+ setPinnedPlayerId("");
+ updateGame({ type: "trim_scores" });
+ if (motionAllowed()) startSlide({ leaving: null, kind: "out" });
+ return;
+ }
+ changeContent(content);
+ }
+
function changeContent(content: Content) {
setListExpanded(false);
if (content !== "plot") setPinnedPlayerId("");
@@ -158,29 +188,38 @@ export function GamePlayPage() {
// Delete any trailing rounds that are all zeros
updateGame({ type: "trim_scores" });
}
- if (content === "keypad" && currentContent !== "keypad") {
+ if (content === "keypad" && tab !== "keypad") {
// When we switch to the keypad, automatically go to the next round
const newRound = lastRound(game) + 1;
updateGame({ type: "add_round", round: newRound });
setCurrentRound(newRound);
setSelectedPlayerId(firstPlayerId);
}
+ // Only when stacked: beside the list, a tab is just changed
+ if (motionAllowed() && isStackedLayout()) {
+ if (listExpanded) {
+ startSlide({ leaving: null, kind: "in" });
+ } else if (content !== currentContent) {
+ const forward =
+ contentButtons.findIndex((button) => button.content === content) >
+ contentButtons.findIndex((button) => button.content === currentContent);
+ startSlide({ leaving: currentContent, kind: forward ? "up" : "drop" });
+ }
+ }
setCurrentContent(content);
}
- function startEditingName() {
- nameBeforeEditing.current = game.name;
- selectGameName.current = true;
- setEditingName(true);
- }
-
- function finishEditingName() {
- setEditingName(false);
- // A game with no name at all would leave nothing to press to name it again
- if (game.name.trim() === "") {
- updateGame({ type: "update_name", newName: nameBeforeEditing.current });
- }
- }
+ // The list is only ever on its own when the tabs are along the bottom, so if that stops being so
+ // (the screen is turned, or its window made wider), the tab that the panel holds is selected again
+ useEffect(() => {
+ const query = window.matchMedia?.("(max-aspect-ratio: 1 / 1)");
+ if (!query) return;
+ const onChange = () => {
+ if (!query.matches) setListExpanded(false);
+ };
+ query.addEventListener?.("change", onChange);
+ return () => query.removeEventListener?.("change", onChange);
+ }, []);
// Select the player `offset` places after the selected one, wrapping around the list
function stepPlayer(offset: number) {
@@ -199,117 +238,14 @@ export function GamePlayPage() {
setCurrentRound(Math.max(0, currentRound - 1));
}
- return (
-
- setEditing(true)}
- onFinishEditing={exitEditMode}
- />
- {/* Not with the keypad, which needs the list beside it to pick who the score is for */}
- {currentContent !== "keypad" && (
-
- )}
-
+ {/* Each has its own size, whatever size the panel is made, so that it slides rather than
+ stretches */}
+ {contentButtons.map(({ content }) =>
+ content === currentContent || content === leavingContent ? (
+
+ {renderContent(content)}
+
+ ) : null,
+ )}
+
-
+ {/* Outside the page, as the page is moved up out of the way of the keyboard, and it is not */}
+ {editing && }
+ >
);
}
diff --git a/web/src/components/game-play-page/edit-players-dialog/EditPlayersDialog.scss b/web/src/components/game-play-page/edit-players-dialog/EditPlayersDialog.scss
new file mode 100644
index 0000000..bd832c0
--- /dev/null
+++ b/web/src/components/game-play-page/edit-players-dialog/EditPlayersDialog.scss
@@ -0,0 +1,261 @@
+@use "sass:color";
+@use "../../../Colors.scss" as *;
+@use "../../../Breakpoints.scss" as *;
+
+$row-height: 40px; // Tall enough to tap
+$player-gap: 8px;
+// Empty space above the first player and below the last, inside the scrolling list. A player being
+// dragged can be pulled a little past either end, and the list would cut it off without this.
+$drag-room: 10px;
+$done-color: color.mix($light-elements, $gray-3, 75%); // The same as the Enter key
+
+@keyframes edit-players-backdrop-in {
+ from {
+ background-color: rgba(black, 0);
+ }
+}
+
+@keyframes edit-players-dialog-in {
+ from {
+ opacity: 0;
+ }
+}
+
+// Over the whole page, and under the color picker and the toasts, which have to be seen over it
+.edit-players-backdrop {
+ position: fixed;
+ inset: 0;
+ z-index: 2;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background-color: rgba(black, 0.75);
+ animation: edit-players-backdrop-in 0.2s ease;
+
+ @media (prefers-reduced-motion: reduce) {
+ &,
+ .edit-players-dialog {
+ animation: none;
+ transition-duration: 0s;
+ }
+ }
+}
+
+.edit-players-dialog {
+ width: min(440px, calc(100% - 32px));
+ // --shift and --fit-height are set by the component, to keep clear of a phone's keyboard
+ max-height: min(calc(100% - 48px), var(--fit-height, 100%));
+ padding: 24px 24px 20px;
+ display: flex;
+ flex-direction: column;
+ background-color: $gray-1;
+ border: 1px solid $gray-4;
+ border-radius: 24px;
+ color: $light-elements;
+ animation: edit-players-dialog-in 0.2s ease;
+ transform: translateY(var(--shift, 0px));
+ transition: transform 0.15s ease-out;
+
+ &:focus {
+ outline: none;
+ }
+
+ @include small-screen {
+ max-height: min(calc(100% - 24px), var(--fit-height, 100%));
+ padding: 18px 16px 16px;
+ }
+
+ .edit-players-title {
+ flex: none;
+ margin: 0 0 12px;
+ font-size: 18pt;
+ font-weight: 700;
+ text-align: center;
+ }
+
+ // Scrolls when there are more players than fit
+ .edit-players-list {
+ flex: 0 1 auto;
+ min-height: 0;
+ margin: 0 -8px;
+ padding: $drag-room 8px;
+ overflow-x: hidden;
+ overflow-y: auto;
+ scrollbar-width: thin;
+ scrollbar-color: $gray-5 transparent;
+ display: flex;
+ flex-direction: column;
+ gap: $player-gap;
+ }
+
+ // What the list says when there is nobody in it
+ .edit-players-empty {
+ padding: 16px 0;
+ color: rgba($light-elements, 0.55);
+ text-align: center;
+
+ .edit-players-empty-title {
+ font-size: 16pt;
+ font-weight: bold;
+ }
+
+ .edit-players-empty-hint {
+ margin-top: 6px;
+ font-size: 11pt;
+ }
+
+ .edit-players-empty-button {
+ color: $light-elements;
+ font-weight: bold;
+ }
+ }
+
+ .edit-player {
+ position: relative;
+ flex: none; // Rows keep their height instead of being squashed to fit
+ height: $row-height;
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ transition: transform 150ms ease;
+
+ &.dragging {
+ z-index: 1;
+ background-color: $gray-2;
+ box-shadow: 0 0 6px 0 black;
+ transition: none;
+ }
+ }
+
+ .drag-handle {
+ flex: none;
+ align-self: stretch;
+ width: $row-height;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ color: $light-elements;
+ cursor: grab;
+ touch-action: none; // Or a finger dragging it would scroll the list instead, and cancel the drag
+ }
+
+ .edit-player.dragging .drag-handle {
+ cursor: grabbing;
+ }
+
+ .player-color {
+ flex: none;
+ align-self: stretch;
+ width: $row-height;
+ border-radius: 2px;
+ cursor: pointer;
+ }
+
+ .player-name-input {
+ flex: 1;
+ width: 0; // Size comes from flex-grow only, not the input's intrinsic width
+ min-width: 0;
+ height: 32px;
+ padding: 0 8px;
+ background-color: $gray-3;
+ border: 1px solid $gray-5;
+ border-radius: 8px;
+ color: $light-elements;
+ font-family: inherit;
+ font-size: 18pt;
+ font-weight: bold;
+
+ &:focus {
+ outline: none;
+ border-color: $light-elements;
+ }
+ }
+
+ .delete-button {
+ flex: none;
+ align-self: stretch;
+ width: $row-height;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ color: $light-elements;
+ cursor: pointer;
+ }
+
+ .edit-players-footer {
+ flex: none;
+ margin-top: 12px;
+ display: flex;
+ justify-content: center;
+ gap: 12px;
+
+ button {
+ min-height: 44px;
+ padding: 0 20px 0 14px;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ border-radius: 12px;
+ cursor: pointer;
+ font-family: inherit;
+ font-size: 15px;
+ font-weight: 600;
+ touch-action: manipulation;
+ -webkit-tap-highlight-color: transparent;
+ transition:
+ transform 60ms ease,
+ background-color 60ms ease,
+ border-color 60ms ease,
+ color 60ms ease;
+
+ &:active {
+ transform: scale(0.94);
+ }
+
+ &:focus-visible {
+ outline: 2px solid $light-elements;
+ outline-offset: 2px;
+ }
+
+ .material-symbols-outlined {
+ font-size: 22px;
+ }
+ }
+
+ // An empty place for another player: a dashed outline that fills in when it is pointed at
+ .add-player-button {
+ background-color: transparent;
+ border: 2px dashed $gray-5;
+ color: rgba($light-elements, 0.75);
+
+ @media (hover: hover) {
+ &:hover {
+ border-color: $light-elements;
+ color: $light-elements;
+ }
+ }
+
+ &:active {
+ border-color: $light-elements;
+ color: $light-elements;
+ }
+ }
+
+ // The way out, so it is as prominent as the Enter key of the keypad
+ .done-button {
+ background-color: $done-color;
+ border: 1px solid $done-color;
+ color: $background;
+
+ @media (hover: hover) {
+ &:hover {
+ filter: brightness(0.94);
+ }
+ }
+
+ &:active {
+ filter: brightness(0.85);
+ }
+ }
+ }
+}
diff --git a/web/src/components/game-play-page/edit-players-dialog/EditPlayersDialog.tsx b/web/src/components/game-play-page/edit-players-dialog/EditPlayersDialog.tsx
new file mode 100644
index 0000000..2118540
--- /dev/null
+++ b/web/src/components/game-play-page/edit-players-dialog/EditPlayersDialog.tsx
@@ -0,0 +1,517 @@
+import "./EditPlayersDialog.scss";
+import clsx from "clsx";
+import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
+import { useGame } from "@/GameContext";
+import { useToast } from "@/ToastContext";
+import { nextPlayerColor, type Scorecard } from "@/Game";
+import { autoScrollSpeed } from "@/utils/autoScroll";
+import { fitShift } from "@/utils/fitInView";
+import { newId } from "@/utils/newId";
+import { SelectColorComponent } from "../player-list-component/SelectColorComponent/SelectColorComponent";
+
+/** How much of the screen has to be covered before it is taken to be a keyboard */
+const MIN_KEYBOARD_HEIGHT = 120;
+
+/** The room to leave between the window and the edge of what the keyboard leaves visible */
+const KEYBOARD_GAP = 12;
+
+/**
+ * A window over the game page for changing the players: renaming, recoloring, reordering, adding
+ * and deleting them. It is not the browser's own dialog, as that would put the color picker and the
+ * toasts (which offer to undo a deletion) underneath it. Closed with Done or Escape, and not by a
+ * press on the page behind, which would lose a half-made change too easily. With `selectFirstName`, as when a new game has just started, the first name is
+ * selected, ready to be typed over.
+ */
+export function EditPlayersDialog({
+ onClose,
+ selectFirstName = false,
+}: {
+ onClose: () => void;
+ selectFirstName?: boolean;
+}) {
+ const { game, updateGame } = useGame();
+ const { showToast } = useToast();
+ const dialogRef = useRef(null);
+ // The player whose name field should be focused as soon as it appears (a just-added player)
+ // On a phone the keyboard is kept up the whole time, so one of the names always has the focus
+ const [touchDevice] = useState(() => window.matchMedia?.("(pointer: coarse)").matches ?? false);
+ const focusPlayerId = useRef(
+ selectFirstName || touchDevice ? (game.scorecards[0]?.id ?? "") : "",
+ );
+ // Whether the name that is focused as the window opens is left alone, as opposed to selected. A
+ // tap that brings up the keyboard would not select it, and selecting it takes the phone's menu.
+ const leaveFirstNameAlone = useRef(touchDevice && !selectFirstName);
+ const lastNameBox = useRef(null);
+ const pickerOpen = useRef(false);
+ const addButtonRef = useRef(null);
+ // Whether a name has just been focused by a press, whose release would move the cursor into it and
+ // so undo the selecting of the whole name
+ const keepNameSelected = useRef(false);
+ // What kind of pointer pressed the name that has the focus, if one did. A selection made by a
+ // finger's tap brings up the phone's own menu (cut, copy, paste) and handles, which is not wanted.
+ const pressedWith = useRef("");
+ const [selectingColorId, setSelectingColorId] = useState("");
+ const [colorPickerPosition, setColorPickerPosition] = useState(null);
+ const [dragId, setDragId] = useState("");
+ const listRef = useRef(null);
+ // While dragging, positions are measured down the whole list, scrolled out of view or not: the
+ // pointer's Y plus how far the list has scrolled. Then scrolling the list under a pointer that's
+ // standing still moves the dragged player along with it.
+ const dragStartY = useRef(0);
+ const pointerY = useRef(0); // The latest position of the pointer on the screen, while dragging
+ const [dragDeltaY, setDragDeltaY] = useState(0);
+ const [playerSpacing, setPlayerSpacing] = useState(0);
+ const playerRefs = useRef
);
}
diff --git a/web/src/components/title-page/TitlePage.scss b/web/src/components/title-page/TitlePage.scss
index 74efe10..f700bf8 100644
--- a/web/src/components/title-page/TitlePage.scss
+++ b/web/src/components/title-page/TitlePage.scss
@@ -188,15 +188,6 @@ $accent: color.mix($light-elements, $gray-3, 75%); // The same as the Enter key
text-transform: uppercase;
}
- .continue-game-name {
- max-width: 100%;
- overflow: hidden;
- font-size: 17pt;
- font-weight: 700;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
-
.continue-game-details {
font-size: 11pt;
font-weight: 500;
@@ -214,8 +205,8 @@ $accent: color.mix($light-elements, $gray-3, 75%); // The same as the Enter key
// away off the left of the screen, or in from it. The card is only on one of the two pages, so it
// only ever has one of these.
// Going to the game is quicker than coming back to the title, as it is the one that is in the way
-$to-title-time: 450ms;
-$to-game-time: 250ms;
+$to-title-time: 350ms;
+$to-game-time: 180ms;
// The lines go sooner than the game page arrives, so that they are not seen through it
$lines-out-time: 120ms;
diff --git a/web/src/components/title-page/TitlePage.tsx b/web/src/components/title-page/TitlePage.tsx
index a619308..5cd5e4a 100644
--- a/web/src/components/title-page/TitlePage.tsx
+++ b/web/src/components/title-page/TitlePage.tsx
@@ -2,9 +2,7 @@ import "./TitlePage.scss";
import { useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import { defaultColors, supportOptions } from "@/config";
-import { isUntouched } from "@/Game";
import { useGame } from "@/GameContext";
-import { useToast } from "@/ToastContext";
import { lastRound } from "@/utils/Scores";
import { runWithTransition, usePageAppeared } from "@/viewTransition";
import { ScoreLinesBackdrop } from "./ScoreLinesBackdrop";
@@ -18,7 +16,6 @@ function plural(count: number, noun: string): string {
export function TitlePage() {
const navigate = useNavigate();
const { game, updateGame, hasGame } = useGame();
- const { showToast } = useToast();
usePageAppeared();
const [supportOpen, setSupportOpen] = useState(false);
const supportLinkRef = useRef(null);
@@ -31,18 +28,8 @@ export function TitlePage() {
}
function startNewGame() {
- const previous = game;
- const losingSomething = hasGame && !isUntouched(previous);
-
runWithTransition(() => {
updateGame({ type: "new_game" });
- if (losingSomething) {
- showToast({
- message: "Started a new game",
- actionLabel: "Undo",
- onAction: () => updateGame({ type: "load_game", game: previous }),
- });
- }
navigate("/play", { state: { newGame: true } });
}, "to-game");
}
@@ -73,7 +60,6 @@ export function TitlePage() {
>
Continue Game
- {game.name}
{plural(game.scorecards.length, "player")} · {plural(lastRound(game), "round")}
diff --git a/web/src/utils/fitInView.test.ts b/web/src/utils/fitInView.test.ts
new file mode 100644
index 0000000..e8824ab
--- /dev/null
+++ b/web/src/utils/fitInView.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it } from "vitest";
+import { fitShift } from "./fitInView";
+
+// A screen 800 high, with the keyboard leaving the top 500 of it
+describe("fitShift", () => {
+ it("leaves a box that is in view where it is", () => {
+ expect(fitShift(0, 100, 300, 0, 500, 12)).toBe(0);
+ });
+
+ it("moves a box up just far enough to clear the keyboard", () => {
+ // Its bottom is at 600, and has to be at 488
+ expect(fitShift(0, 300, 300, 0, 500, 12)).toBe(-112);
+ });
+
+ it("keeps a box that was moved up where it is, when it still fits", () => {
+ expect(fitShift(-112, 300, 300, 0, 500, 12)).toBe(-112);
+ });
+
+ it("moves it up further if the keyboard needs more of the room", () => {
+ expect(fitShift(-112, 300, 300, 0, 400, 12)).toBe(-212);
+ });
+
+ it("does not take a box off the top of what is visible", () => {
+ // Too tall to fit: it is stopped at the top margin rather than pushed up out of sight
+ expect(fitShift(-500, 300, 300, 0, 300, 12)).toBe(-288);
+ });
+
+ it("allows for the visible part starting lower down than the top of the page", () => {
+ expect(fitShift(0, 100, 300, 200, 700, 12)).toBe(112);
+ });
+});
diff --git a/web/src/utils/fitInView.ts b/web/src/utils/fitInView.ts
new file mode 100644
index 0000000..ca0154a
--- /dev/null
+++ b/web/src/utils/fitInView.ts
@@ -0,0 +1,19 @@
+/**
+ * How far a box that is `shift` down from where it would otherwise sit (negative is up) needs to be
+ * moved to be seen between the top and the bottom of what is visible, with `margin` to spare. The
+ * `top` and `height` are those of the box without the shift. A box that is in view already is left
+ * where it is, rather than brought back to the middle, so this is only ever what is needed.
+ */
+export function fitShift(
+ shift: number,
+ top: number,
+ height: number,
+ visibleTop: number,
+ visibleBottom: number,
+ margin: number,
+): number {
+ const furthestUp = visibleTop + margin - top;
+ const furthestDown = visibleBottom - margin - (top + height);
+ // If it is too tall to fit, the top of it is what is kept in view
+ return Math.max(furthestUp, Math.min(furthestDown, shift));
+}