Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Since the `1.0.0-beta` release, the version in `package.json` has stayed at `1.0

### Fixed

- **Input Mode picker:** opening board options keeps the selected mode stable.
- **Dashboard ladders:** “Your ladders” table shows pagination and page-size controls when you belong to more than 10 ladders (full list still comes from `me_dashboard`; only the first page was visible before).

## [1.0.0-ci] - 2026-11-22
Expand Down
12 changes: 6 additions & 6 deletions src/components/InputModeOptionsPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ function InputModeOptionsPicker({
const [allModes, allModesSetter] = useState([]);
const initialUidRef = useRef(initialUid);
const lastEmittedRef = useRef(null);
const initDoneRef = useRef(false);
const initializedGroupDataRef = useRef(null);
const { t } = useTranslation();

/** @type {[string | undefined, React.Dispatch<React.SetStateAction<string | undefined>>]} */
const [ungroupedChoice, ungroupedChoiceSetter] = useState(undefined);

useEffect(() => {
initialUidRef.current = initialUid;
initDoneRef.current = false;
initializedGroupDataRef.current = null;
if (metaGame === undefined || metaGame === null || metaGame === "") {
groupDataSetter([]);
allModesSetter([]);
Expand Down Expand Up @@ -155,7 +155,6 @@ function InputModeOptionsPicker({
ungroupedChoiceSetter(pick);
groupVariantsSetter({});
lastEmittedRef.current = pick;
initDoneRef.current = true;
} else {
const applied = applySanitizedInputModeSelection(
sanitized,
Expand All @@ -167,8 +166,8 @@ function InputModeOptionsPicker({
const first =
sanitized.find((u) => !u.startsWith("#")) ?? sanitized[0] ?? undefined;
lastEmittedRef.current = first;
initDoneRef.current = true;
}
initializedGroupDataRef.current = builtGroupData;
}, [metaGame, initialUid]);

const handleGroupChange = useCallback((group, variant) => {
Expand All @@ -193,7 +192,8 @@ function InputModeOptionsPicker({
}, [activeUids, allModes, disableFields]);

useEffect(() => {
if (!initDoneRef.current) {
// This effect can still see the render before initialization queued its state.
if (initializedGroupDataRef.current !== groupData) {
return;
}
if (allModes.length === 0) {
Expand Down Expand Up @@ -236,7 +236,7 @@ function InputModeOptionsPicker({
allModes,
disableFields,
groupVariants,
groupData.length,
groupData,
metaGame,
onChange,
]);
Expand Down
62 changes: 62 additions & 0 deletions src/components/InputModeOptionsPicker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import InputModeOptionsPicker from "./InputModeOptionsPicker";

vi.mock("@abstractplay/gameslib", async (importOriginal) => {
const flat = [
{ uid: "basic", name: "Basic" },
{ uid: "advanced", name: "Advanced" },
];
const grouped = flat.map((mode) => ({ ...mode, group: "entry" }));
const gameinfo = new Map(
[
["flat", flat],
["grouped", grouped],
].map(([uid, inputModes]) => [uid, { uid, inputModes, playercounts: [2] }]),
);
return {
...(await importOriginal()),
gameinfo,
GameFactory: (uid) => ({
inputModes: () => gameinfo.get(uid).inputModes,
}),
};
});

vi.mock("react-i18next", async (importOriginal) => ({
...(await importOriginal()),
useTranslation: () => ({ t: (key) => key }),
}));

describe("InputModeOptionsPicker", () => {
it.each([
["flat", 2],
["grouped", 3],
])("keeps the initial %s selection local until the user changes it", (metaGame, count) => {
const onChange = vi.fn();
const { rerender } = render(
<InputModeOptionsPicker metaGame={metaGame} initialUid="basic" onChange={onChange} />,
);

expect(screen.getAllByRole("radio")).toHaveLength(count);
expect(screen.getByRole("radio", { name: "Basic" })).toBeChecked();
expect(onChange).not.toHaveBeenCalled();

const advanced = screen.getByRole("radio", { name: "Advanced" });
fireEvent.click(advanced);
expect(advanced).toBeChecked();
expect(onChange).toHaveBeenCalledExactlyOnceWith("advanced");

rerender(
<InputModeOptionsPicker metaGame={metaGame} initialUid="advanced" onChange={onChange} />,
);
expect(advanced).toBeChecked();
expect(onChange).toHaveBeenCalledTimes(1);

rerender(
<InputModeOptionsPicker metaGame={metaGame} initialUid="basic" onChange={onChange} />,
);
expect(screen.getByRole("radio", { name: "Basic" })).toBeChecked();
expect(onChange).toHaveBeenCalledTimes(1);
});
});