@hadoku/game-ui 0.1.154 → 0.1.155

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.
@@ -33,7 +33,13 @@ export interface RoomCoreClient<R> {
33
33
  get(roomId: string): Promise<R | null>;
34
34
  create(body: Record<string, unknown>): Promise<RoomOutcome<R>>;
35
35
  join(roomId: string, password?: string): Promise<RoomJoinOutcome<R>>;
36
- leave(roomId: string): Promise<RoomOutcome<R>>;
36
+ /**
37
+ * `POST /api/rooms/:id/leave`. Mid-tournament the server refuses it unless `drop` says the caller is
38
+ * leaving the tournament on purpose (the room's own Leave, confirmed): a way off the page never drops anyone.
39
+ */
40
+ leave(roomId: string, opts?: {
41
+ drop?: boolean;
42
+ }): Promise<RoomOutcome<R>>;
37
43
  ready(roomId: string, ready: boolean): Promise<RoomOutcome<R>>;
38
44
  close(roomId: string): Promise<RoomEndOutcome>;
39
45
  reset(roomId: string): Promise<RoomEndOutcome>;
@@ -109,7 +109,7 @@ export function roomCoreClient({ parse, fetch: fetchImpl = pageFetch, base = api
109
109
  return { ok: false, reason: 'error', message: 'The server answered the join with something that is not a room.' };
110
110
  return { ok: true, room };
111
111
  },
112
- leave: (roomId) => send(`${id(roomId)}/leave`, {}, 'Could not leave the room'),
112
+ leave: (roomId, opts) => send(`${id(roomId)}/leave${opts?.drop === true ? '?drop=1' : ''}`, {}, 'Could not leave the room'),
113
113
  ready: (roomId, ready) => send(`${id(roomId)}/ready`, { ready }, 'Could not change your readiness'),
114
114
  close: (roomId) => end(roomId, 'close', 'Could not close the room'),
115
115
  reset: (roomId) => end(roomId, 'reset', 'Could not reset the room'),
@@ -18,6 +18,11 @@ export interface RoomShellProps {
18
18
  * head row draws Leave, and the page's top bar leaves through it too (`room-exit.tsx`).
19
19
  */
20
20
  leave?: LeaveRoom;
21
+ /**
22
+ * Leaving now costs the viewer their place in an event (a tournament under way), and this is what the
23
+ * leave is called: Leave reads so, asks once more before it leaves, and the top bar only goes home.
24
+ */
25
+ leaveAsks?: string;
21
26
  /** Close, Settings, and whatever the game type's own settings panel wants beside them. */
22
27
  headerTools: ReactNode;
23
28
  streamed: boolean;
@@ -40,4 +45,4 @@ export interface RoomShellProps {
40
45
  /** The game type's own content: its setup, its game, in that order. */
41
46
  children: ReactNode;
42
47
  }
43
- export declare function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, leave, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }: RoomShellProps): import("react").JSX.Element;
48
+ export declare function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, leave, leaveAsks, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }: RoomShellProps): import("react").JSX.Element;
@@ -15,15 +15,30 @@ import { useState } from 'react';
15
15
  import { leaveRoomThen, useRoomHome, useRoomLeave } from "./room-exit.js";
16
16
  import '../../components/Button.css';
17
17
  import './RoomShell.css';
18
- export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, leave, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }) {
19
- useRoomLeave(leave ?? null);
18
+ export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled, leave, leaveAsks, headerTools, streamed, streamedSubLine, resolved, pending, pendingBody, streamedBody, locked, password, onPasswordChange, onPasswordSubmit, roomMissingMessage, children, }) {
19
+ useRoomLeave(leaveAsks === undefined ? (leave ?? null) : null);
20
20
  const home = useRoomHome();
21
- const [leaving, setLeaving] = useState(false);
22
- return (_jsxs("div", { ref: shellRef, className: "shell shell--fit", "data-testid": "constructed", "data-members": dataMembers, children: [_jsxs("header", { className: "shell__head", children: [roomTitle !== undefined ? (_jsx("h1", { className: "shell__title", "data-testid": "room-name", children: roomTitle })) : settled ? (_jsx("h1", { className: "shell__title", children: "Room" })) : (_jsx("span", { className: "skeleton skeleton--title" })), roomTitle !== undefined && titleAside, _jsxs("div", { className: "shell__tools", children: [leave !== undefined && home !== null && (_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave", disabled: leaving, onClick: () => {
23
- setLeaving(true);
24
- void leaveRoomThen(home);
25
- }, children: _jsx("span", { className: "ct-action__label", children: "Leave" }) })), headerTools] }), resolved && streamed && streamedSubLine] }), _jsxs("main", { className: "lobby lobby--room", "aria-busy": pending ? 'true' : undefined, children: [pending && pendingBody, streamed && streamedBody, !streamed && resolved && (_jsxs(_Fragment, { children: [locked !== null && (_jsxs("form", { className: "lobby__locked ct-panel", "data-testid": "room-locked", onSubmit: (e) => {
21
+ return (_jsxs("div", { ref: shellRef, className: "shell shell--fit", "data-testid": "constructed", "data-members": dataMembers, children: [_jsxs("header", { className: "shell__head", children: [roomTitle !== undefined ? (_jsx("h1", { className: "shell__title", "data-testid": "room-name", children: roomTitle })) : settled ? (_jsx("h1", { className: "shell__title", children: "Room" })) : (_jsx("span", { className: "skeleton skeleton--title" })), roomTitle !== undefined && titleAside, _jsxs("div", { className: "shell__tools", children: [leave !== undefined && home !== null && _jsx(RoomLeave, { leave: leave, asks: leaveAsks, home: home }), headerTools] }), resolved && streamed && streamedSubLine] }), _jsxs("main", { className: "lobby lobby--room", "aria-busy": pending ? 'true' : undefined, children: [pending && pendingBody, streamed && streamedBody, !streamed && resolved && (_jsxs(_Fragment, { children: [locked !== null && (_jsxs("form", { className: "lobby__locked ct-panel", "data-testid": "room-locked", onSubmit: (e) => {
26
22
  e.preventDefault();
27
23
  onPasswordSubmit();
28
24
  }, children: [_jsx("p", { role: "alert", children: locked === 'need' ? 'This room needs a password.' : locked === 'wrong' ? 'Wrong password.' : 'Too many attempts.' }), _jsx("label", { htmlFor: "room-password", children: "Password" }), _jsx("input", { id: "room-password", "data-testid": "room-password", type: "password", autoComplete: "off", value: password, onChange: (e) => onPasswordChange(e.target.value) }), _jsx("button", { type: "submit", "data-testid": "room-password-submit", disabled: locked === 'rate-limited', children: "Join" })] })), locked === null && roomMissingMessage !== null && (_jsx("p", { className: "ct-error", role: "alert", "data-testid": "room-missing", children: roomMissingMessage })), children] }))] })] }));
29
25
  }
26
+ /** The head row's Leave. A leave that costs an event (`asks`) is asked once more, by its name, before it leaves. */
27
+ function RoomLeave({ leave, asks, home }) {
28
+ const [leaving, setLeaving] = useState(false);
29
+ const [asking, setAsking] = useState(false);
30
+ if (asks === undefined || !asking) {
31
+ return (_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave", disabled: leaving, onClick: () => {
32
+ if (asks !== undefined) {
33
+ setAsking(true);
34
+ return;
35
+ }
36
+ setLeaving(true);
37
+ void leaveRoomThen(home);
38
+ }, children: _jsx("span", { className: "ct-action__label", children: asks ?? 'Leave' }) }));
39
+ }
40
+ return (_jsxs("span", { className: "room-leave__ask", "data-testid": "room-leave-ask", children: [_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave-no", autoFocus: true, disabled: leaving, onClick: () => setAsking(false), children: _jsx("span", { className: "ct-action__label", children: "Cancel" }) }), _jsx("button", { type: "button", className: "room-leave ct-action ct-action--danger", "data-testid": "room-leave-yes", disabled: leaving, onClick: () => {
41
+ setLeaving(true);
42
+ void leave().finally(home);
43
+ }, children: _jsx("span", { className: "ct-action__label", children: asks }) })] }));
44
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.154",
4
- "gitHead": "c0edfe5c5672ea00e058c777deeccc8963eba558",
3
+ "version": "0.1.155",
4
+ "gitHead": "57586f6329004b90a6811e9fbea44892db00bc76",
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.",
@@ -54,8 +54,8 @@
54
54
  "react-dom": "^19.2.8"
55
55
  },
56
56
  "dependencies": {
57
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.158",
58
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.158",
57
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.159",
58
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.159",
59
59
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
60
60
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.143",
61
61
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.143",