Support current battle choice promises and persistent notices
Verify and publish checkpoint container / container (push) Successful in 11m42s
Verify and publish checkpoint container / container (push) Successful in 11m42s
This commit is contained in:
1 parent
77d02b3231
commit
bd8377d87b
16 files changed
+684
-32
No files matched your search
+25
-27
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useState, useEffect, useCallback, useReducer, useRef } from 'react';
|
||||
import { TableTalk } from '@/components/table-talk';
|
||||
import { ActionableNotice } from '@/components/actionable-notice';
|
||||
import { RemovedRoomNotice } from '@/components/removed-room-notice';
|
||||
import { GameTable } from '@/components/game-table';
|
||||
import { SeatConfirmation, type SeatConfirmationKind } from '@/components/seat-confirmation';
|
||||
@@ -10,6 +11,7 @@ import { TwoPlayerControls } from '@/components/two-player-controls';
|
||||
import { FactionAllocation } from '@/components/faction-allocation';
|
||||
import { FactionSwap } from '@/components/faction-swap';
|
||||
import { randomId } from '@/lib/random-id';
|
||||
import { initialActionableNotices, updateActionableNotices } from '@/lib/actionable-notices';
|
||||
import {
|
||||
SeatHandoverSetup,
|
||||
SeatHandoverClaim,
|
||||
@@ -87,7 +89,10 @@ export default function Home() {
|
||||
const [expansions, setExpansions] = useState<string[]>([]);
|
||||
const [name, setName] = useState('');
|
||||
const [code, setCode] = useState('');
|
||||
const [notice, setNotice] = useState('');
|
||||
const [noticeQueue, updateNoticeQueue] = useReducer(updateActionableNotices, initialActionableNotices);
|
||||
const notice = noticeQueue.items[0] ?? null;
|
||||
const setNotice = useCallback((text: string) => updateNoticeQueue({type:'enqueue',text}), []);
|
||||
const dismissNotice = useCallback((id: number) => updateNoticeQueue({type:'dismiss',id}), []);
|
||||
const [seatConfirmation, setSeatConfirmation] = useState<SeatConfirmationKind | null>(null);
|
||||
const [entryConfirmation, setEntryConfirmation] = useState<{ kind: 'create' | 'join'; code: string } | null>(null);
|
||||
const seatClaimUncertain = useRef(false);
|
||||
@@ -113,7 +118,7 @@ export default function Home() {
|
||||
removedRooms.current.add(room);
|
||||
++epoch.current;
|
||||
recovery.current = null; botAttempt.current = null;
|
||||
setRemovedRoom(room); setNeedsReconcile(false); setBotRecovery(false); setConnection(''); setNotice('');
|
||||
setRemovedRoom(room); setNeedsReconcile(false); setBotRecovery(false); setConnection('');
|
||||
}, []);
|
||||
useEffect(() => subscribeRoomRemoval(markRoomRemoved), [markRoomRemoved]);
|
||||
// This function is deliberately GET-only, including WebMCP reads and recovery.
|
||||
@@ -352,7 +357,7 @@ export default function Home() {
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [refresh]);
|
||||
}, [refresh, setNotice]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!roomCode || removedRoom === roomCode) return;
|
||||
@@ -399,7 +404,6 @@ export default function Home() {
|
||||
return;
|
||||
const requestEpoch = ++epoch.current;
|
||||
mutationPending.current = true;
|
||||
setNotice('');
|
||||
setBusy(true);
|
||||
try {
|
||||
const data = await requestJson<GameView>(roomEntryUrl(attempt), {
|
||||
@@ -535,7 +539,6 @@ export default function Home() {
|
||||
setEntryConfirmation(null);
|
||||
setRemovedRoom(null);
|
||||
setRestoreFailed(false);
|
||||
setNotice('');
|
||||
window.history.replaceState(null, '', '/');
|
||||
}
|
||||
|
||||
@@ -575,7 +578,6 @@ export default function Home() {
|
||||
requestEpoch = epoch.current;
|
||||
mutationPending.current = true;
|
||||
setBusy(true);
|
||||
setNotice('');
|
||||
try {
|
||||
const data = await requestJson<GameView>(`/api/rooms/${room}`, {
|
||||
method: 'POST',
|
||||
@@ -633,7 +635,6 @@ export default function Home() {
|
||||
setGame(null);
|
||||
setRestoring(true);
|
||||
setRestoreFailed(false);
|
||||
setNotice('');
|
||||
void refresh(room, true).catch((error: Error) => {
|
||||
if (activeRoom.current === room && activeSeat.current === seat) {
|
||||
setRestoreFailed(true);
|
||||
@@ -649,7 +650,6 @@ export default function Home() {
|
||||
const requestEpoch = epoch.current;
|
||||
mutationPending.current = true;
|
||||
setBusy(true);
|
||||
setNotice('');
|
||||
let responseReceived = false;
|
||||
try {
|
||||
const data = await requestJson<GameView & { entryReceipt?: { operationId: string; replayed: boolean } }>(`/api/rooms/${attempt.room}`, {
|
||||
@@ -727,7 +727,6 @@ export default function Home() {
|
||||
const data = await refresh(room, true);
|
||||
if (restoreFailed && activeRoom.current === room) {
|
||||
setRestoreFailed(false);
|
||||
setNotice('');
|
||||
}
|
||||
if (resumeBots) await advanceBots(data, true);
|
||||
} catch (error) {
|
||||
@@ -799,7 +798,6 @@ export default function Home() {
|
||||
setNeedsReconcile(false);
|
||||
setRestoreFailed(false);
|
||||
setConnection('');
|
||||
setNotice('');
|
||||
return true;
|
||||
}
|
||||
useEffect(() => {
|
||||
@@ -837,6 +835,7 @@ export default function Home() {
|
||||
if (showHandover)
|
||||
return (
|
||||
<main className="table-shell">
|
||||
<ActionableNotice notice={notice} onDismiss={dismissNotice} />
|
||||
<SeatHandoverClaim
|
||||
onCancel={() => window.location.reload()}
|
||||
onRestored={(view) => {
|
||||
@@ -930,14 +929,14 @@ export default function Home() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{!roomUnavailable && (notice || connection || needsReconcile || botRecovery) && (
|
||||
<output className="floating-notice">
|
||||
{notice && <span>{notice}</span>}
|
||||
{connection && <span>{connection}</span>}
|
||||
{needsReconcile && (
|
||||
{(notice || (!roomUnavailable && (connection || needsReconcile || botRecovery))) && (
|
||||
<div className="floating-notice" aria-live="polite">
|
||||
<ActionableNotice notice={notice} onDismiss={dismissNotice} />
|
||||
{!roomUnavailable && connection && <span>{connection}</span>}
|
||||
{!roomUnavailable && needsReconcile && (
|
||||
<span>Actions paused until the current table is confirmed.</span>
|
||||
)}
|
||||
{(connection || needsReconcile) && (
|
||||
{!roomUnavailable && (connection || needsReconcile) && (
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={busy || checkingConnection}
|
||||
@@ -946,7 +945,7 @@ export default function Home() {
|
||||
Reconnect
|
||||
</Button>
|
||||
)}
|
||||
{botRecovery && (
|
||||
{!roomUnavailable && botRecovery && (
|
||||
<>
|
||||
<span>
|
||||
AI progress was not confirmed. Check the table before
|
||||
@@ -961,10 +960,7 @@ export default function Home() {
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<button onClick={() => setNotice('')} aria-label="Dismiss message">
|
||||
×
|
||||
</button>
|
||||
</output>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
@@ -976,7 +972,7 @@ export default function Home() {
|
||||
DUNE<span>ARRAKIS TABLE</span>
|
||||
</div>
|
||||
</header>
|
||||
{removedRoom ? <RemovedRoomNotice code={removedRoom} busy={checkingConnection} onRetry={() => void reconnect()} onExit={() => { removedRooms.current.delete(removedRoom); activeRoom.current = null; activeSeat.current = null; ++epoch.current; setRestoreFailed(false); setRemovedRoom(null); setConnection(''); setNotice(''); window.history.replaceState(null, '', '/'); }} /> : <section className="notice">
|
||||
{removedRoom ? <RemovedRoomNotice code={removedRoom} busy={checkingConnection} onRetry={() => void reconnect()} onExit={() => { removedRooms.current.delete(removedRoom); activeRoom.current = null; activeSeat.current = null; ++epoch.current; setRestoreFailed(false); setRemovedRoom(null); setConnection(''); window.history.replaceState(null, '', '/'); }} /> : <section className="notice">
|
||||
<h1>
|
||||
{restoring
|
||||
? 'Restoring your table'
|
||||
@@ -985,8 +981,9 @@ export default function Home() {
|
||||
<output aria-live="polite">
|
||||
{restoring
|
||||
? 'Checking your saved seat and the latest game state…'
|
||||
: connection || notice}
|
||||
: connection}
|
||||
</output>
|
||||
<ActionableNotice notice={notice} onDismiss={dismissNotice} />
|
||||
{restoreFailed && !restoring && (
|
||||
<>
|
||||
<p>
|
||||
@@ -1006,7 +1003,6 @@ export default function Home() {
|
||||
activeRoom.current = null;
|
||||
setRestoreFailed(false);
|
||||
setConnection('');
|
||||
setNotice('');
|
||||
}}
|
||||
>
|
||||
Open join form
|
||||
@@ -1014,6 +1010,7 @@ export default function Home() {
|
||||
</>
|
||||
)}
|
||||
</section>}
|
||||
{removedRoom && <ActionableNotice notice={notice} onDismiss={dismissNotice} />}
|
||||
</main>
|
||||
);
|
||||
// A first request is progress, not recovery. Keep the actionable recovery
|
||||
@@ -1027,6 +1024,7 @@ export default function Home() {
|
||||
<section className="notice">
|
||||
<h1>{entryAttempt.kind === 'create' ? 'Creating your room…' : 'Joining the room…'}</h1>
|
||||
<output aria-live="polite">Please wait.</output>
|
||||
<ActionableNotice notice={notice} onDismiss={dismissNotice} />
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
@@ -1063,7 +1061,7 @@ export default function Home() {
|
||||
not start a new attempt. No request is retried automatically.
|
||||
</p>
|
||||
{entryProblem && <p role="alert">{entryProblem}</p>}
|
||||
{notice && <output aria-live="polite">{notice}</output>}
|
||||
<ActionableNotice notice={notice} onDismiss={dismissNotice} />
|
||||
{entryAttempt && (
|
||||
<Button
|
||||
disabled={busy || claimUncertain}
|
||||
@@ -1328,7 +1326,7 @@ export default function Home() {
|
||||
preserve its exact details.
|
||||
</output>
|
||||
)}
|
||||
{notice && <output className="notice">{notice}</output>}
|
||||
{notice && <div className="notice"><ActionableNotice notice={notice} onDismiss={dismissNotice} /></div>}
|
||||
<div className="table-note">
|
||||
<Globe size={18} />
|
||||
<span>
|
||||
|
||||
Reference in new issue
Block a user