@hadoku/game-ui 0.1.210 → 0.1.212

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /* `Modal.tsx`: the room list's create form's look (`../rooms/rooms.css`), for any modal. */
1
+ /* `Modal.tsx`'s look; the room front's create dialog retunes it (`../front/RoomFront.css`). */
2
2
 
3
3
  .ct-modal {
4
4
  position: fixed;
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import './Modal.css';
3
- export declare function Modal({ title, testId, onClose, children, actions, wide, }: {
3
+ export declare function Modal({ title, testId, onClose, children, actions, wide, panelClassName, }: {
4
4
  title: string;
5
5
  testId: string;
6
6
  /** Absent: a question that must be answered through its `actions`. */
@@ -9,4 +9,6 @@ export declare function Modal({ title, testId, onClose, children, actions, wide,
9
9
  actions?: ReactNode;
10
10
  /** A reading panel (long text) rather than a short question: wider than the default. */
11
11
  wide?: boolean;
12
+ /** The panel's surface classes, after its own `ct-modal__panel`: a caller with its own paint (the room front's create dialog) passes its own. */
13
+ panelClassName?: string;
12
14
  }): import("react").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*
3
- * A titled panel over a dimmed page, drawn the way the room list's create form is (`../rooms/RoomList.tsx`):
3
+ * A titled panel over a dimmed page (the room front's create dialog is one, `../front/RoomFront.tsx`):
4
4
  * Escape, its close button and a press on the backdrop close it. With no `onClose` it cannot be put
5
5
  * away, only answered: no close button, and Escape and the backdrop do nothing. Its `actions`, when it
6
6
  * has any, sit along its foot, the affirmative last (bottom right).
@@ -12,7 +12,7 @@ import { Icon } from '@wolffm/themes';
12
12
  import { uiLength } from '@wolffm/ui-shell/settings';
13
13
  import { OverPage } from "./OverPage.js";
14
14
  import './Modal.css';
15
- export function Modal({ title, testId, onClose, children, actions, wide = false, }) {
15
+ export function Modal({ title, testId, onClose, children, actions, wide = false, panelClassName = 'ct-surface ct-panel', }) {
16
16
  const titleId = useId();
17
17
  useEffect(() => {
18
18
  if (onClose === undefined)
@@ -27,5 +27,5 @@ export function Modal({ title, testId, onClose, children, actions, wide = false,
27
27
  return (_jsx(OverPage, { children: _jsx("div", { className: "ct-modal", "data-testid": `${testId}-backdrop`, onPointerDown: (e) => {
28
28
  if (e.target === e.currentTarget)
29
29
  onClose?.();
30
- }, children: _jsxs("div", { className: "ct-modal__panel ct-surface ct-panel", "data-wide": wide || undefined, "data-testid": testId, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, children: [_jsxs("div", { className: "ct-modal__head", children: [_jsx("h3", { id: titleId, children: title }), onClose !== undefined && (_jsx("button", { type: "button", className: "ct-modal__close", "aria-label": "Close", "data-testid": `${testId}-close`, onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) }))] }), children, actions !== undefined && _jsx("div", { className: "ct-modal__actions", children: actions })] }) }) }));
30
+ }, children: _jsxs("div", { className: `ct-modal__panel ${panelClassName}`, "data-wide": wide || undefined, "data-testid": testId, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, children: [_jsxs("div", { className: "ct-modal__head", children: [_jsx("h3", { id: titleId, children: title }), onClose !== undefined && (_jsx("button", { type: "button", className: "ct-modal__close", "aria-label": "Close", "data-testid": `${testId}-close`, onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) }))] }), children, actions !== undefined && _jsx("div", { className: "ct-modal__actions", children: actions })] }) }) }));
31
31
  }
@@ -568,32 +568,25 @@
568
568
  /* ── the create dialog ───────────────────────────────────────────────── */
569
569
 
570
570
  /*
571
- * Not under `.rooms`: the dialog portals into `<body>` (`OverPage`), so no rule here may be scoped
572
- * under the page, and its custom properties are read from `:root`.
571
+ * `Modal` (`../components/Modal.tsx`) with `room-front-create` on its panel. Not under `.rooms`: it
572
+ * portals into `<body>` (`OverPage`), so no rule here may be scoped under the page, and its custom
573
+ * properties are read from `:root`. Each rule out-ranks `Modal.css`'s own by a class, whichever
574
+ * sheet loads first. The backdrop's rule names this panel first: it reaches only the backdrop that
575
+ * holds it, so it is this block's (`css-ownership.test.ts`), not `Modal`'s.
573
576
  */
574
- .rooms__backdrop {
575
- position: fixed;
576
- inset: 0;
577
+ :has(> .room-front-create).ct-modal {
577
578
  z-index: var(--room-front-create-z, var(--z-modal, 50));
578
- display: flex;
579
- align-items: center;
580
- justify-content: center;
581
579
  padding: var(--room-front-create-inset, 16px);
582
- background: var(--color-bg-overlay);
583
580
  }
584
581
 
585
582
  /*
586
583
  * The panel. Its surface (fill, edge, shadow) is `:where()`-light, so a game's own raised-surface
587
584
  * class passed as `createPanelClassName` draws over it regardless of which sheet loads first.
588
585
  */
589
- .room-front-create {
590
- display: flex;
591
- flex-direction: column;
586
+ .room-front-create.ct-modal__panel {
592
587
  gap: var(--room-front-create-gap, 6px);
593
588
  box-sizing: var(--room-front-create-box, border-box);
594
589
  width: min(420px, 100%);
595
- max-height: calc(100dvh - 32px);
596
- overflow-y: auto;
597
590
  padding: var(--room-front-create-padding, 16px 20px 20px);
598
591
  border-radius: var(--room-front-create-radius, var(--hdk-radius-lg));
599
592
  color: var(--room-front-create-ink, inherit);
@@ -606,33 +599,28 @@
606
599
  box-shadow: var(--room-front-create-shadow, var(--hdk-shadow-lg));
607
600
  }
608
601
 
609
- .rooms__create-head {
610
- display: flex;
611
- align-items: center;
612
- justify-content: space-between;
602
+ /* Its fields are the panel's own flex items, after the head. */
603
+ .room-front-create__form {
604
+ display: contents;
605
+ }
606
+
607
+ .room-front-create .ct-modal__head {
613
608
  margin-bottom: var(--room-front-create-head-gap, 4px);
614
609
  }
615
610
 
616
- .rooms__create-head h3 {
617
- margin: 0;
611
+ .room-front-create .ct-modal__head h3 {
618
612
  font-size: var(--room-front-create-title-size, 16px);
619
613
  font-weight: var(--room-front-create-title-weight, 600);
620
614
  }
621
615
 
622
- .rooms__create-close {
623
- display: inline-flex;
624
- align-items: center;
625
- justify-content: center;
616
+ .room-front-create .ct-modal__close {
626
617
  padding: var(--room-front-create-close-padding, 4px);
627
618
  border: var(--room-front-create-close-border, 1px solid transparent);
628
- border-radius: var(--hdk-radius-sm);
629
- background: transparent;
630
619
  color: var(--room-front-create-close-ink, inherit);
631
- cursor: pointer;
632
620
  }
633
621
 
634
- .rooms__create-close:hover,
635
- .rooms__create-close:focus-visible {
622
+ .room-front-create .ct-modal__close:hover,
623
+ .room-front-create .ct-modal__close:focus-visible {
636
624
  border-color: var(--room-front-create-close-hover-border, var(--color-border));
637
625
  background: var(--room-front-create-close-hover-bg, transparent);
638
626
  color: var(--room-front-create-close-hover-ink, inherit);
@@ -664,7 +652,7 @@
664
652
  }
665
653
 
666
654
  .room-front-create input:focus-visible,
667
- .room-front-create .rooms__create-close:focus-visible {
655
+ .room-front-create .ct-modal__close:focus-visible {
668
656
  outline-style: var(--room-front-create-focus-outline, solid);
669
657
  box-shadow: var(--room-front-create-focus-shadow, none);
670
658
  }
@@ -126,12 +126,6 @@ export interface RoomFrontProps<V extends RoomFrontRoom> {
126
126
  gameTypes: readonly RoomFrontGameType[];
127
127
  createFields?: (kind: string) => RoomFrontCreateSlot | null;
128
128
  rowExtras?: (room: V) => RoomFrontRowExtras;
129
- /** A Twitch-like banner above the list — omitted draws none of its markup (no wrapper element). */
130
- banner?: ReactNode;
131
- /** The header's own tools row — omitted draws no `<nav>` at all. */
132
- navTools?: ReactNode;
133
- /** A slot beside `banner`, for a caller with no fused banner of its own — omitted draws nothing. */
134
- featured?: ReactNode;
135
129
  onOpenRoom: (id: string) => void;
136
130
  /** Extra content in the list's own head row, beside the title and before Create room (a game's own filter bar, say). */
137
131
  headExtras?: ReactNode;
@@ -186,4 +180,4 @@ export interface RoomFrontProps<V extends RoomFrontRoom> {
186
180
  */
187
181
  createPanelClassName?: string;
188
182
  }
189
- export declare function RoomFront<V extends RoomFrontRoom>({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed, matches: matchesFilter, beforeOpenRoom, nameMaxLength, passwordMaxLength, testingStorageKey, defaultName, onSectionRef, createPanelClassName, }: RoomFrontProps<V>): import("react").JSX.Element;
183
+ export declare function RoomFront<V extends RoomFrontRoom>({ rooms: client, gameTypes, createFields, rowExtras, onOpenRoom, headExtras, actionsExtras, feed, matches: matchesFilter, beforeOpenRoom, nameMaxLength, passwordMaxLength, testingStorageKey, defaultName, onSectionRef, createPanelClassName, }: RoomFrontProps<V>): import("react").JSX.Element;
@@ -21,12 +21,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
21
21
  * into `<body>`) and a row's own colours with `RoomFrontRowExtras.vars`, never with a copy of it.
22
22
  */
23
23
  import { useCallback, useContext, useEffect, useRef, useState } from 'react';
24
- import { Icon } from '@wolffm/themes';
25
24
  import { Avatar, faceOf } from "../components/Avatar.js";
26
- import { OverPage } from "../components/OverPage.js";
25
+ import { Modal } from "../components/Modal.js";
27
26
  import { RadioCards } from "../components/RadioCards.js";
28
27
  import { TopLayer } from "../topLayer.js";
29
- import { uiLength } from '@wolffm/ui-shell/settings';
30
28
  import { Reveal } from '@wolffm/ui-shell/components';
31
29
  import * as storage from '@wolffm/ui-shell/storage';
32
30
  import { FrontGateContext, usePartShown } from "./gate.js";
@@ -39,21 +37,6 @@ import './RoomFront.css';
39
37
  const DEFAULT_NAME_MAX = 60;
40
38
  const DEFAULT_PASSWORD_MAX = 200;
41
39
  const DEFAULT_TESTING_KEY = 'room-front.testingFolded';
42
- /**
43
- * Whether `node` is one of React's own "renders nothing" values — `null`, `undefined`, `false`,
44
- * `''`, or an array holding only such values — rather than merely `!== undefined`. The settled
45
- * contract's own words: "empty or absent renders nothing (no wrapper element)" for `banner`,
46
- * `navTools` and `featured` — `undefined` is one way a caller omits a slot, but `null`, `false`
47
- * and `[]` are the others a caller passes when it computes the slot conditionally (`cond && <X/>`,
48
- * or `cond ? <X/> : null`), and each must draw no wrapper of its own either.
49
- */
50
- function isRenderable(node) {
51
- if (node === null || node === undefined || node === false || node === '')
52
- return false;
53
- if (Array.isArray(node))
54
- return node.some(isRenderable);
55
- return true;
56
- }
57
40
  /** Whether the viewer is already a member — a room never hides its own occupant's name from them. */
58
41
  const isMine = (room) => room.members.some((m) => m.id === room.you.id);
59
42
  const normalRooms = (rooms) => rooms.filter((r) => r.testing !== true);
@@ -62,7 +45,7 @@ const testingRooms = (rooms) => rooms.filter((r) => r.testing === true);
62
45
  function orderByMatch(rooms, matches) {
63
46
  return [...rooms.filter(matches), ...rooms.filter((r) => !matches(r))];
64
47
  }
65
- export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed = roomFeed(), matches: matchesFilter, beforeOpenRoom, nameMaxLength = DEFAULT_NAME_MAX, passwordMaxLength = DEFAULT_PASSWORD_MAX, testingStorageKey = DEFAULT_TESTING_KEY, defaultName, onSectionRef, createPanelClassName, }) {
48
+ export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, onOpenRoom, headExtras, actionsExtras, feed = roomFeed(), matches: matchesFilter, beforeOpenRoom, nameMaxLength = DEFAULT_NAME_MAX, passwordMaxLength = DEFAULT_PASSWORD_MAX, testingStorageKey = DEFAULT_TESTING_KEY, defaultName, onSectionRef, createPanelClassName, }) {
66
49
  const [state, setState] = useState({ kind: 'loading' });
67
50
  const [creating, setCreating] = useState(false);
68
51
  const [testingFolded, setTestingFolded] = useState(() => storage.remembered(testingStorageKey, (raw) => raw === '1') ?? false);
@@ -120,10 +103,10 @@ export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, b
120
103
  if (drawnRooms !== null)
121
104
  remember({ rooms: drawnRooms });
122
105
  }, [drawnRooms, remember]);
123
- return (_jsxs(_Fragment, { children: [isRenderable(navTools) && _jsx("nav", { className: "shell__tools", children: navTools }), isRenderable(featured) && featured, isRenderable(banner) && banner, _jsxs("section", { className: "rooms ct-panel", "data-testid": "rooms", "aria-labelledby": "rooms-title", "aria-busy": !shown, ref: onSectionRef, children: [_jsxs("div", { className: "rooms__head", children: [_jsx("h2", { id: "rooms-title", className: "rooms__title ct-panel__title", children: "Rooms" }), headExtras, _jsxs("span", { className: "rooms__actions", children: [_jsx("button", { type: "button", className: "room-front__go", "data-testid": "room-create-open", "aria-haspopup": "dialog", onClick: () => {
124
- playRole('ui.select');
125
- setCreating(true);
126
- }, children: "Create room" }), actionsExtras] })] }), _jsxs(Reveal, { name: "rooms", shown: shown, skeleton: _jsx(RoomGhosts, { count: shape.rooms }), layerClassName: "rooms__layer", children: [state.kind === 'failed' && (_jsxs("div", { className: "rooms__status rooms__status--bad", role: "alert", "data-testid": "rooms-error", children: [_jsx("p", { children: state.message }), _jsx("button", { type: "button", "data-testid": "rooms-retry", onClick: retry, children: "Retry" })] })), state.kind === 'ready' && normal.length === 0 && testing.length === 0 && (_jsx("p", { className: "rooms__status", "data-testid": "rooms-empty", children: "No rooms yet." })), state.kind === 'ready' && normal.length > 0 && (_jsx("ul", { className: "rooms__list", "data-testid": "room-list", children: orderedNormal.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) })), state.kind === 'ready' && testing.length > 0 && (_jsxs("div", { "data-testid": "rooms-testing", children: [_jsx("h3", { className: "rooms__title ct-panel__title", children: _jsxs("button", { type: "button", className: "rooms__fold", "aria-expanded": !testingFolded, "aria-controls": "room-list-testing", "data-testid": "rooms-testing-fold", onClick: toggleTesting, children: [_jsx("svg", { className: "rooms__fold-chevron", width: "14", height: "14", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M9 5l7 7-7 7" }) }), "Testing"] }) }), !testingFolded && (_jsx("ul", { className: "rooms__list", id: "room-list-testing", "data-testid": "room-list-testing", children: orderedTesting.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) }))] })), state.kind === 'ready' && state.stale !== null && (_jsx("p", { className: "rooms__stale", "data-testid": "rooms-stale", children: "List may be out of date." }))] }), creating && (_jsx(CreateRoomDialog, { client: client, gameTypes: gameTypes, createFields: createFields, onClose: () => setCreating(false), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, nameMaxLength: nameMaxLength, defaultName: defaultName, surfaceClassName: createPanelClassName === undefined ? 'room-front-create' : `room-front-create ${createPanelClassName}` })), _jsx(TopLayer, { fixed: true })] })] }));
106
+ return (_jsxs("section", { className: "rooms ct-panel", "data-testid": "rooms", "aria-labelledby": "rooms-title", "aria-busy": !shown, ref: onSectionRef, children: [_jsxs("div", { className: "rooms__head", children: [_jsx("h2", { id: "rooms-title", className: "rooms__title ct-panel__title", children: "Rooms" }), headExtras, _jsxs("span", { className: "rooms__actions", children: [_jsx("button", { type: "button", className: "room-front__go", "data-testid": "room-create-open", "aria-haspopup": "dialog", onClick: () => {
107
+ playRole('ui.select');
108
+ setCreating(true);
109
+ }, children: "Create room" }), actionsExtras] })] }), _jsxs(Reveal, { name: "rooms", shown: shown, skeleton: _jsx(RoomGhosts, { count: shape.rooms }), layerClassName: "rooms__layer", children: [state.kind === 'failed' && (_jsxs("div", { className: "rooms__status rooms__status--bad", role: "alert", "data-testid": "rooms-error", children: [_jsx("p", { children: state.message }), _jsx("button", { type: "button", "data-testid": "rooms-retry", onClick: retry, children: "Retry" })] })), state.kind === 'ready' && normal.length === 0 && testing.length === 0 && (_jsx("p", { className: "rooms__status", "data-testid": "rooms-empty", children: "No rooms yet." })), state.kind === 'ready' && normal.length > 0 && (_jsx("ul", { className: "rooms__list", "data-testid": "room-list", children: orderedNormal.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) })), state.kind === 'ready' && testing.length > 0 && (_jsxs("div", { "data-testid": "rooms-testing", children: [_jsx("h3", { className: "rooms__title ct-panel__title", children: _jsxs("button", { type: "button", className: "rooms__fold", "aria-expanded": !testingFolded, "aria-controls": "room-list-testing", "data-testid": "rooms-testing-fold", onClick: toggleTesting, children: [_jsx("svg", { className: "rooms__fold-chevron", width: "14", height: "14", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M9 5l7 7-7 7" }) }), "Testing"] }) }), !testingFolded && (_jsx("ul", { className: "rooms__list", id: "room-list-testing", "data-testid": "room-list-testing", children: orderedTesting.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) }))] })), state.kind === 'ready' && state.stale !== null && (_jsx("p", { className: "rooms__stale", "data-testid": "rooms-stale", children: "List may be out of date." }))] }), creating && (_jsx(CreateRoomDialog, { client: client, gameTypes: gameTypes, createFields: createFields, onClose: () => setCreating(false), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, nameMaxLength: nameMaxLength, defaultName: defaultName, surfaceClassName: createPanelClassName === undefined ? 'room-front-create' : `room-front-create ${createPanelClassName}` })), _jsx(TopLayer, { fixed: true })] }));
127
110
  }
128
111
  /* ── until the list arrives ─────────────────────────────────────────── */
129
112
  function RoomGhosts({ count }) {
@@ -245,14 +228,6 @@ function CreateRoomDialog({ client, gameTypes, createFields, onClose, onOpenRoom
245
228
  // `RadioCards` wants `{ value, label }`; the settled contract wants `{ id, label }` — this is the
246
229
  // one place the two meet.
247
230
  const kindOptions = gameTypes.map((g) => ({ value: g.id, label: g.label }));
248
- useEffect(() => {
249
- const onKey = (event) => {
250
- if (event.key === 'Escape')
251
- onClose();
252
- };
253
- globalThis.document?.addEventListener('keydown', onKey);
254
- return () => globalThis.document?.removeEventListener('keydown', onKey);
255
- }, [onClose]);
256
231
  const opened = async (outcome) => {
257
232
  if (!outcome.ok) {
258
233
  setBusy(false);
@@ -285,11 +260,8 @@ function CreateRoomDialog({ client, gameTypes, createFields, onClose, onOpenRoom
285
260
  setError(null);
286
261
  await opened(await client.create({ name: trimmed, gameType: kind, ...(slot?.body ?? {}) }));
287
262
  };
288
- return (_jsx(OverPage, { children: _jsx("div", { className: "rooms__backdrop", "data-testid": "room-create-backdrop", onPointerDown: (e) => {
289
- if (e.target === e.currentTarget)
290
- onClose();
291
- }, children: _jsxs("form", { className: surfaceClassName, "data-testid": "room-create", role: "dialog", "aria-modal": "true", "aria-labelledby": "room-create-title", autoComplete: "off", onSubmit: (e) => void submit(e), children: [_jsxs("div", { className: "rooms__create-head", children: [_jsx("h3", { id: "room-create-title", children: "Create a room" }), _jsx("button", { type: "button", className: "rooms__create-close", "aria-label": "Close", "data-testid": "room-create-close", onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) })] }), kindOptions.length > 1 && (_jsxs(_Fragment, { children: [_jsx("span", { className: "rooms__caption", children: "Game type" }), _jsx(RadioCards, { name: "room-create-type", label: "Game type", options: kindOptions, value: kind, onChange: setKind, testId: "room-create-type" })] })), !nameless && (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: "room-create-name", children: "Name" }), _jsx("input", { id: "room-create-name", "data-testid": "room-create-name", value: name, maxLength: nameMaxLength, placeholder: "Friday night", autoComplete: "nickname", autoFocus: true, onChange: (e) => {
292
- setTyped(e.target.value);
293
- setError(null);
294
- } })] })), slot?.node, _jsx("button", { type: "submit", className: "room-front__go", "data-testid": "room-create-submit", disabled: busy || !ready, children: "Create room" }), error !== null && (_jsx("p", { className: "ct-error rooms__error", role: "alert", "data-testid": "room-create-error", children: error }))] }) }) }));
263
+ return (_jsx(Modal, { title: "Create a room", testId: "room-create", onClose: onClose, panelClassName: surfaceClassName, children: _jsxs("form", { className: "room-front-create__form", autoComplete: "off", onSubmit: (e) => void submit(e), children: [kindOptions.length > 1 && (_jsxs(_Fragment, { children: [_jsx("span", { className: "rooms__caption", children: "Game type" }), _jsx(RadioCards, { name: "room-create-type", label: "Game type", options: kindOptions, value: kind, onChange: setKind, testId: "room-create-type" })] })), !nameless && (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: "room-create-name", children: "Name" }), _jsx("input", { id: "room-create-name", "data-testid": "room-create-name", value: name, maxLength: nameMaxLength, placeholder: "Friday night", autoComplete: "nickname", autoFocus: true, onChange: (e) => {
264
+ setTyped(e.target.value);
265
+ setError(null);
266
+ } })] })), slot?.node, _jsx("button", { type: "submit", className: "room-front__go", "data-testid": "room-create-submit", disabled: busy || !ready, children: "Create room" }), error !== null && (_jsx("p", { className: "ct-error rooms__error", role: "alert", "data-testid": "room-create-error", children: error }))] }) }));
295
267
  }
@@ -11,14 +11,54 @@ type PollsClient = Pick<ReturnType<typeof pollsClient>, 'list'>;
11
11
  /** Tests swap the client (and reset the store) here. */
12
12
  export declare function setPollsClient(next: PollsClient): void;
13
13
  /** Tell `listener` the polls now and on every change; answers the unsubscribe. */
14
- export declare function subscribePolls(listener: (polls: Poll[] | null) => void): () => void;
14
+ export declare const subscribePolls: (listener: (items: {
15
+ title: string;
16
+ status: "closed" | "open";
17
+ id: string;
18
+ url: string;
19
+ schema: {
20
+ name: string;
21
+ version: number;
22
+ };
23
+ closesAt: string | null;
24
+ createdBy: string | null;
25
+ attachedBy: string;
26
+ mine: boolean;
27
+ windows: {
28
+ at: string;
29
+ endsAt: string;
30
+ free: number;
31
+ pick: string | null;
32
+ }[];
33
+ createdById?: string | undefined;
34
+ }[] | null) => void) => () => void;
15
35
  /** Re-read the polls and tell every reader. A failed read keeps what they have; a read overtaken by a newer one changes nothing. */
16
- export declare function refreshPolls(): Promise<void>;
36
+ export declare const refreshPolls: () => Promise<void>;
17
37
  /**
18
38
  * A form just attached (Create event's Load form, or Rally's return trip): it shows at once, and
19
39
  * the list is re-read behind it, never left to the next tick.
20
40
  */
21
41
  export declare function pollAttached(form: Poll): Promise<void>;
22
42
  /** The open polls, kept fresh while mounted and shown (`../visible.ts`): `null` until the first read answers. */
23
- export declare function usePolls(): Poll[] | null;
43
+ export declare const usePolls: () => {
44
+ title: string;
45
+ status: "closed" | "open";
46
+ id: string;
47
+ url: string;
48
+ schema: {
49
+ name: string;
50
+ version: number;
51
+ };
52
+ closesAt: string | null;
53
+ createdBy: string | null;
54
+ attachedBy: string;
55
+ mine: boolean;
56
+ windows: {
57
+ at: string;
58
+ endsAt: string;
59
+ free: number;
60
+ pick: string | null;
61
+ }[];
62
+ createdById?: string | undefined;
63
+ }[] | null;
24
64
  export {};
@@ -4,10 +4,9 @@
4
4
  * (`AttachedForm`). The server decides which are listed: the open ones, and to whoever attached it
5
5
  * a closed one still waiting for its event. Its Open button goes to the form on Rally.
6
6
  */
7
- import { useEffect, useState } from 'react';
8
7
  import { AttachedFormSchema } from '@wolffm/platform-wire/events';
9
8
  import { apiUrl, bodyOf, getJson, isRecord, serverMessage } from "../http.js";
10
- import { rereadWhileVisible } from "../visible.js";
9
+ import { createSharedList } from "./shared-list.js";
11
10
  const defaultFetch = (input, init) => fetch(input, init);
12
11
  export function pollsClient(fetchImpl = defaultFetch) {
13
12
  return {
@@ -30,66 +29,26 @@ export function bySoonestClose(polls) {
30
29
  const closes = (p) => (p.closesAt === null ? Infinity : Date.parse(p.closesAt));
31
30
  return [...polls].sort((a, b) => closes(a) - closes(b));
32
31
  }
33
- /** `null` until the first read answers; the last good list after a failed read. */
34
- let current = null;
35
- const listeners = new Set();
36
32
  let client = pollsClient();
37
- /** Bumped by every read and every attach: only the newest read may set the list, so a read begun before an attach never drops its form. */
38
- let generation = 0;
33
+ /** How often a mounted reader re-reads the polls, so another organizer's form shows without a reload (as `./events.ts` does). */
34
+ const REFRESH_MS = 60_000;
35
+ const polls = createSharedList(async () => bySoonestClose(await client.list()), REFRESH_MS);
39
36
  /** Tests swap the client (and reset the store) here. */
40
37
  export function setPollsClient(next) {
41
38
  client = next;
42
- current = null;
43
- generation += 1;
44
- }
45
- function publish(polls) {
46
- current = polls;
47
- for (const listener of listeners)
48
- listener(current);
39
+ polls.reset();
49
40
  }
50
41
  /** Tell `listener` the polls now and on every change; answers the unsubscribe. */
51
- export function subscribePolls(listener) {
52
- listeners.add(listener);
53
- listener(current);
54
- return () => listeners.delete(listener);
55
- }
42
+ export const subscribePolls = polls.subscribe;
56
43
  /** Re-read the polls and tell every reader. A failed read keeps what they have; a read overtaken by a newer one changes nothing. */
57
- export async function refreshPolls() {
58
- const mine = ++generation;
59
- let next;
60
- try {
61
- next = bySoonestClose(await client.list());
62
- }
63
- catch {
64
- // Not reachable for a moment: the page keeps what it showed, or says there are none.
65
- if (current !== null || mine !== generation)
66
- return;
67
- next = [];
68
- }
69
- if (mine === generation)
70
- publish(next);
71
- }
44
+ export const refreshPolls = polls.refresh;
72
45
  /**
73
46
  * A form just attached (Create event's Load form, or Rally's return trip): it shows at once, and
74
47
  * the list is re-read behind it, never left to the next tick.
75
48
  */
76
49
  export async function pollAttached(form) {
77
- generation += 1;
78
- publish(bySoonestClose([...(current ?? []).filter((p) => p.id !== form.id), form]));
50
+ polls.publish(bySoonestClose([...(polls.current() ?? []).filter((p) => p.id !== form.id), form]));
79
51
  await refreshPolls();
80
52
  }
81
- /** How often a mounted reader re-reads the polls, so another organizer's form shows without a reload (as `./events.ts` does). */
82
- const REFRESH_MS = 60_000;
83
53
  /** The open polls, kept fresh while mounted and shown (`../visible.ts`): `null` until the first read answers. */
84
- export function usePolls() {
85
- const [polls, setPolls] = useState(current);
86
- useEffect(() => {
87
- const stop = subscribePolls(setPolls);
88
- const stopReread = rereadWhileVisible(() => void refreshPolls(), REFRESH_MS);
89
- return () => {
90
- stop();
91
- stopReread();
92
- };
93
- }, []);
94
- return polls;
95
- }
54
+ export const usePolls = polls.use;
@@ -0,0 +1,14 @@
1
+ /** The list `read` answers, re-read every `refreshMs` while a reader is mounted and the tab is shown (`../visible.ts`). */
2
+ export declare function createSharedList<T>(read: () => Promise<T[]>, refreshMs: number): {
3
+ current: () => T[] | null;
4
+ /** Tell `listener` the list now and on every change; answers the unsubscribe. */
5
+ subscribe(listener: (items: T[] | null) => void): () => void;
6
+ /** Re-read the list and tell every reader. A failed read keeps what they have; a read overtaken by a newer one changes nothing. */
7
+ refresh(): Promise<void>;
8
+ /** Set the list now: a read begun before it cannot take it away. */
9
+ publish(items: T[]): void;
10
+ /** Back to unread, and any read in flight overtaken (tests swap their client here). */
11
+ reset(): void;
12
+ /** The list, kept fresh while mounted and shown: `null` until the first read answers. */
13
+ use(): T[] | null;
14
+ };
@@ -0,0 +1,69 @@
1
+ /*
2
+ * One list the page reads from the server and every reader shares (the front page's events and
3
+ * polls): a read tells every reader at once, and only the newest read or `publish` may set the
4
+ * list, so a slow read never overwrites a newer one.
5
+ */
6
+ import { useEffect, useState } from 'react';
7
+ import { rereadWhileVisible } from "../visible.js";
8
+ /** The list `read` answers, re-read every `refreshMs` while a reader is mounted and the tab is shown (`../visible.ts`). */
9
+ export function createSharedList(read, refreshMs) {
10
+ /** `null` until the first read answers; the last good list after a failed read. */
11
+ let current = null;
12
+ const listeners = new Set();
13
+ /** Bumped by every read, publish and reset: only the newest may set the list. */
14
+ let generation = 0;
15
+ const tell = (items) => {
16
+ current = items;
17
+ for (const listener of listeners)
18
+ listener(current);
19
+ };
20
+ const list = {
21
+ current: () => current,
22
+ /** Tell `listener` the list now and on every change; answers the unsubscribe. */
23
+ subscribe(listener) {
24
+ listeners.add(listener);
25
+ listener(current);
26
+ return () => listeners.delete(listener);
27
+ },
28
+ /** Re-read the list and tell every reader. A failed read keeps what they have; a read overtaken by a newer one changes nothing. */
29
+ async refresh() {
30
+ const mine = ++generation;
31
+ let next;
32
+ try {
33
+ next = await read();
34
+ }
35
+ catch {
36
+ // Not reachable for a moment: the page keeps what it showed, or, never read at all, an empty list.
37
+ if (current !== null || mine !== generation)
38
+ return;
39
+ next = [];
40
+ }
41
+ if (mine === generation)
42
+ tell(next);
43
+ },
44
+ /** Set the list now: a read begun before it cannot take it away. */
45
+ publish(items) {
46
+ generation += 1;
47
+ tell(items);
48
+ },
49
+ /** Back to unread, and any read in flight overtaken (tests swap their client here). */
50
+ reset() {
51
+ current = null;
52
+ generation += 1;
53
+ },
54
+ /** The list, kept fresh while mounted and shown: `null` until the first read answers. */
55
+ use() {
56
+ const [items, setItems] = useState(current);
57
+ useEffect(() => {
58
+ const stop = list.subscribe(setItems);
59
+ const stopReread = rereadWhileVisible(() => void list.refresh(), refreshMs);
60
+ return () => {
61
+ stop();
62
+ stopReread();
63
+ };
64
+ }, []);
65
+ return items;
66
+ },
67
+ };
68
+ return list;
69
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.210",
4
- "gitHead": "a345f20d57cd3911ef0d07a5133eabab359dcd15",
3
+ "version": "0.1.212",
4
+ "gitHead": "c6d631372431f2405813a11f78c6e6d82c300ac7",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
@@ -53,8 +53,8 @@
53
53
  "react-dom": "^19.2.8"
54
54
  },
55
55
  "dependencies": {
56
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.214",
57
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.214",
56
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.216",
57
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.216",
58
58
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
59
59
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.152",
60
60
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",