Keep last round's summary visible until all bids are placed
The round summary used to disappear after a fixed 5 seconds. It is now derived from the game state: the previous round's result is shown while the new round is in bidding and hides once card play starts. This also survives a page reload. - Drop the client-side round timer from useWizard - On narrow screens show the summary in the page flow so it does not cover the bid buttons Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,6 @@ import type {
|
||||
GameOptions,
|
||||
GameView,
|
||||
Lobby,
|
||||
RoundResult,
|
||||
ServerMessage,
|
||||
TrickResult,
|
||||
} from './types'
|
||||
@@ -20,7 +19,6 @@ export interface Toast {
|
||||
// Per tab, so several tabs can act as different players; survives reloads.
|
||||
const TOKEN_KEY = 'wizard.token'
|
||||
const TRICK_DISPLAY_MS = 2200
|
||||
const ROUND_DISPLAY_MS = 5000
|
||||
const TOAST_MS = 4000
|
||||
const MAX_RETRY_DELAY_MS = 10000
|
||||
// Close code the server uses when the session was opened in another tab.
|
||||
@@ -60,8 +58,6 @@ export function useWizard() {
|
||||
const [game, setGame] = useState<GameView | null>(null)
|
||||
// The most recently completed trick, shown for a moment before it is cleared.
|
||||
const [completedTrick, setCompletedTrick] = useState<TrickResult | null>(null)
|
||||
// Result of the round that just ended, shown as a short summary.
|
||||
const [completedRound, setCompletedRound] = useState<RoundResult | null>(null)
|
||||
const [toasts, setToasts] = useState<Toast[]>([])
|
||||
|
||||
const socketRef = useRef<WebSocket | null>(null)
|
||||
@@ -82,7 +78,6 @@ export function useWizard() {
|
||||
let attempt = 0
|
||||
let retryTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let trickTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let roundTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
const handleMessage = (message: ServerMessage) => {
|
||||
switch (message.type) {
|
||||
@@ -99,16 +94,7 @@ export function useWizard() {
|
||||
clearTimeout(trickTimer)
|
||||
trickTimer = setTimeout(() => setCompletedTrick(null), TRICK_DISPLAY_MS)
|
||||
}
|
||||
const round = message.events.find((event) => event.type === 'round_completed')
|
||||
if (round) {
|
||||
setCompletedRound(round.result)
|
||||
clearTimeout(roundTimer)
|
||||
roundTimer = setTimeout(() => setCompletedRound(null), ROUND_DISPLAY_MS)
|
||||
}
|
||||
if (!message.game) {
|
||||
setCompletedTrick(null)
|
||||
setCompletedRound(null)
|
||||
}
|
||||
if (!message.game) setCompletedTrick(null)
|
||||
break
|
||||
}
|
||||
case 'error':
|
||||
@@ -155,7 +141,6 @@ export function useWizard() {
|
||||
disposed = true
|
||||
clearTimeout(retryTimer)
|
||||
clearTimeout(trickTimer)
|
||||
clearTimeout(roundTimer)
|
||||
socketRef.current?.close()
|
||||
socketRef.current = null
|
||||
}
|
||||
@@ -188,7 +173,7 @@ export function useWizard() {
|
||||
[send],
|
||||
)
|
||||
|
||||
return { status, playerId, lobby, game, completedTrick, completedRound, toasts, dismissToast, actions }
|
||||
return { status, playerId, lobby, game, completedTrick, toasts, dismissToast, actions }
|
||||
}
|
||||
|
||||
export type WizardActions = ReturnType<typeof useWizard>['actions']
|
||||
|
||||
Reference in New Issue
Block a user