fix(ui): no-op when re-selecting the turn already on screen
Tests · UI / test (push) Waiting to run
Tests · UI / test (pull_request) Successful in 3m35s

Clicking the current-turn row in the header turn navigator while
already viewing it routed through returnToCurrent() →
viewTurn(currentTurn), which re-fetches the live report and flips the
view through `loading`. At turn 0 the only row is the live turn, so
the dropdown always fired a pointless backend round-trip and redraw.

Guard goToTurn() against re-selecting the on-screen turn
(turn === viewedTurn): just close the popover and stop. Leaving
history is unaffected — there the viewed turn differs from the target.

Closes #45

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-26 00:18:30 +02:00
parent b957d17022
commit e82c9f8bbd
3 changed files with 53 additions and 3 deletions
@@ -12,7 +12,10 @@ drawer below the 768 px breakpoint, mirroring `view-menu.svelte`.
Selecting a row calls `gameState.viewTurn(N)`; the row that matches
`currentTurn` delegates to `gameState.returnToCurrent()` so the
"leave history" path always flows through one method.
"leave history" path always flows through one method. Selecting the
row already on screen (`viewedTurn`) is a pure no-op — most visibly
at turn 0, where the sole row is the live turn — so the navigator
never re-fetches the report just to redraw the same snapshot.
-->
<script lang="ts">
import { getContext, onMount } from "svelte";
@@ -64,6 +67,13 @@ Selecting a row calls `gameState.viewTurn(N)`; the row that matches
async function goToTurn(turn: number): Promise<void> {
open = false;
if (gameState === undefined) return;
// Re-selecting the turn already on screen changes nothing, so just
// close the popover. Without this guard the current-turn row routes
// through `returnToCurrent()` → `viewTurn(currentTurn)`, which
// re-fetches the live report and flips the view through `loading` —
// most visibly at turn 0, where the only row is the live turn.
// Leaving history still works: there the viewed turn differs.
if (turn === gameState.viewedTurn) return;
if (turn === gameState.currentTurn) {
await gameState.returnToCurrent();
return;