Skip to content

Commit 84d2ef3

Browse files
committed
Fix mobile replay and stabilize phone controls
1 parent 1e5bca0 commit 84d2ef3

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/components/Board.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export function Board({ flipped = false }: Props) {
6161
};
6262

6363
const lastMove = state.history[state.history.length - 1];
64-
const moveIndex = state.history.length;
64+
// Include replay nonce so "Replay" re-mounts animated pieces and restarts keyframes.
65+
const moveAnimIndex = state.history.length + lastMoveReplayNonce;
6566
const checkedKing = result.kind === "ongoing" && inCheck(state, state.turn)
6667
? findKing(state, state.turn)
6768
: null;
@@ -125,7 +126,7 @@ export function Board({ flipped = false }: Props) {
125126
["--slide-dx" as string]: `${sign * df * 100}%`,
126127
["--slide-dy" as string]: `${sign * dr * 100}%`
127128
};
128-
slideKey = `slide-${moveIndex}-${lastMoveReplayNonce}`;
129+
slideKey = `slide-${moveAnimIndex}`;
129130
}
130131
const isRematerializeHere =
131132
isTeleportMove &&
@@ -154,7 +155,7 @@ export function Board({ flipped = false }: Props) {
154155
)}
155156
{piece && (
156157
<span
157-
key={isRematerializeHere ? `remat-${moveIndex}-${lastMoveReplayNonce}` : slideKey}
158+
key={isRematerializeHere ? `remat-${moveAnimIndex}` : slideKey}
158159
className={
159160
isRematerializeHere
160161
? "piece-wrap piece-rematerialize"
@@ -174,7 +175,7 @@ export function Board({ flipped = false }: Props) {
174175
)}
175176
{isDematerializeHere && lastMove && (
176177
<span
177-
key={`demat-${moveIndex}-${lastMoveReplayNonce}`}
178+
key={`demat-${moveAnimIndex}`}
178179
className="piece-wrap piece-dematerialize"
179180
aria-hidden="true"
180181
>
@@ -187,7 +188,7 @@ export function Board({ flipped = false }: Props) {
187188
</span>
188189
)}
189190
{isLastTo && lastMove?.captured && store.settings.explodeOnCapture && (
190-
<span key={`boom-${moveIndex}-${lastMoveReplayNonce}`} className="boom" aria-hidden="true">
191+
<span key={`boom-${moveAnimIndex}`} className="boom" aria-hidden="true">
191192
<span className="boom-core">💥</span>
192193
<span className="boom-bit b1"></span>
193194
<span className="boom-bit b2"></span>

src/styles.css

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ section label { display: block; margin: 6px 0; }
486486
.timer-control:hover { filter: brightness(1.2); }
487487
.clock-side {
488488
flex: 1;
489+
min-width: 0;
489490
background: var(--panel);
490491
padding: 8px 12px;
491492
border-radius: 10px;
@@ -494,6 +495,12 @@ section label { display: block; margin: 6px 0; }
494495
align-items: center;
495496
border: 1px solid transparent;
496497
}
498+
.clock-side > span {
499+
min-width: 0;
500+
overflow: hidden;
501+
text-overflow: ellipsis;
502+
white-space: nowrap;
503+
}
497504
.clock-side.active { border-color: var(--accent); }
498505
.clock-side strong { font-variant-numeric: tabular-nums; font-size: 1.1rem; }
499506
.clock-side strong.low { color: #ef4444; animation: check-pulse 900ms ease-in-out infinite; }
@@ -536,9 +543,40 @@ section label { display: block; margin: 6px 0; }
536543
margin: 12px 0;
537544
gap: 8px;
538545
}
539-
.controls .status { font-weight: 600; }
546+
.controls .status {
547+
font-weight: 600;
548+
line-height: 1.25;
549+
}
540550
.controls .buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
541551

552+
@media (max-width: 640px) {
553+
.controls {
554+
flex-direction: column;
555+
align-items: stretch;
556+
}
557+
558+
.controls .status {
559+
min-height: 2.5em;
560+
}
561+
562+
.controls .buttons {
563+
display: grid;
564+
grid-template-columns: repeat(3, minmax(0, 1fr));
565+
justify-content: stretch;
566+
width: 100%;
567+
}
568+
569+
.controls .buttons button {
570+
width: 100%;
571+
min-width: 0;
572+
padding: 8px 6px;
573+
font-size: 0.9rem;
574+
white-space: nowrap;
575+
overflow: hidden;
576+
text-overflow: ellipsis;
577+
}
578+
}
579+
542580
.movelist ol {
543581
list-style: none;
544582
padding: 0;

0 commit comments

Comments
 (0)