Skip to content
Merged
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
24 changes: 23 additions & 1 deletion ui/rounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ let wanted: string | null = null;
let drawn = "";
let drawnFull = "";
let redraw = () => {};
// A pointer press is down. A row selects on `pointerdown`, so the round can open under the press, and its release, outside the dialog,
// would light-dismiss (`closedby="any"`) the dialog it just opened: the dialog waits for the release (`opensAfterPress`).
let pressed = false;
let opensAfterPress = false;

// The full-size view's `<dialog>` (`index.html`), modal over the map.
const dialogOf = () => element("round-full") as HTMLDialogElement;
Expand All @@ -97,6 +101,20 @@ export function startRounds(again: () => void) {
const dialog = dialogOf();
dialog.addEventListener("close", closed);
lightDismiss(dialog);
document.addEventListener(
"pointerdown",
() => {
pressed = true;
},
true,
);
const released = () => {
pressed = false;
// After the `click` that follows the release, which the same task dispatches.
if (opensAfterPress) setTimeout(() => redraw(), 0);
};
document.addEventListener("pointerup", released, true);
document.addEventListener("pointercancel", released, true);
}

// Daniel closed the full-size view: the minimized view is back, the focus on the line of the question it showed, since the control that
Expand All @@ -116,6 +134,7 @@ function closed() {
// The view lets go of the full-size view: the round left, or another took it.
function shut(dialog: HTMLDialogElement) {
full = null;
opensAfterPress = false;
drawnFull = "";
if (dialog.open) dialog.close();
dialog.replaceChildren();
Expand Down Expand Up @@ -428,7 +447,10 @@ export function drawRoundView(selected: Selection | null): string | null {
drawnFull = state;
swap(dialog, [fullHeadOf(round, session), bodyOf(round, form, session, message), barOf(round, form, session, copied)]);
}
if (!dialog.open) dialog.showModal();
if (!dialog.open) {
opensAfterPress = pressed;
if (!pressed) dialog.showModal();
}
}
return key;
}
Expand Down
17 changes: 16 additions & 1 deletion ui/tests/rounds.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { connect, fakeDocument, Live } from "./dom.mjs";

mock.timers.enable({ apis: ["setInterval", "Date"], now: 1_800_000_000_000 });
const page = new Map();
// The page's document-level listeners, by event, for the tests that press and release a pointer.
const listeners = new Map();
const byId = (id) => page.get(id) ?? page.set(id, connect(document.createElement("div"))).get(id);
globalThis.document = fakeDocument(
{
getElementById: byId,
body: { dataset: {}, classList: { contains: () => true, add() {}, remove() {}, toggle() {} } },
visibilityState: "visible",
addEventListener() {},
addEventListener: (name, run) => void listeners.set(name, run),
},
Live,
);
Expand Down Expand Up @@ -136,6 +138,19 @@ test("an open round arriving in Decision mode shows the minimized view, one line
dialog().close();
});

// Selecting on a row's `pointerdown` opens the round while the button is still down; a release outside the dialog then light-dismisses
// (`closedby="any"`) the dialog it has just opened. So the dialog waits for the release.
test("a round that opens while a pointer press is down opens after its release, not under it", async () => {
await draw(sessionOf(), [roundOf()]);
listeners.get("pointerdown")?.({ button: 0 });
openFull();
assert.equal(dialog().open, false, "not opened under the press");
listeners.get("pointerup")?.({ button: 0 });
await new Promise((done) => setTimeout(done, 5));
assert.equal(dialog().open, true, "opened once the press is over");
dialog().close();
});

// A waiting plan takes the plan view's element from the minimized round: none of the minimized view's layout stays on it.
test("a waiting plan that takes the view from a minimized round drops the minimized layout", async () => {
await draw(sessionOf({ id: "m1", resume_id: "m1" }), [roundOf({ session_id: "m1" })]);
Expand Down
Loading