Fix avanzamento quarto basket e regia senza cronometro.

Normalizza il periodo nel backend quando l'app invia "Q1" via cable, così advance_period aggiorna regia e overlay; rimuove i controlli cronometro dalla regia e rende più tollerante il decode iOS al resume sessione.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Emiliano Frascaro
2026-06-20 16:15:44 +02:00
parent c92099a41b
commit 793cfaaaf1
18 changed files with 861 additions and 452 deletions

View File

@@ -35,7 +35,8 @@
modalCancel: document.getElementById("modal-cancel"),
preview: document.getElementById("regia-preview"),
previewPlaceholder: document.getElementById("regia-preview-placeholder"),
btnPause: document.getElementById("btn-pause")
btnPause: document.getElementById("btn-pause"),
subtitle: document.getElementById("regia-subtitle")
};
let pendingAction = null;
@@ -99,6 +100,31 @@
return `${m}:${String(s).padStart(2, "0")}`;
}
function resolvePeriodLabel(score, board) {
const raw = score.period;
if (typeof raw === "string" && raw.trim()) return raw.trim();
if (typeof raw === "number" && raw > 0) {
return board === "basket" ? `Q${raw}` : `${raw}° tempo`;
}
const nested = score.data || {};
const dataPeriod = nested.period ?? nested["period"];
const periodNum = parseInt(dataPeriod, 10);
if (periodNum > 0) {
if (nested.overtime || nested["overtime"]) {
return board === "basket" ? `OT${Math.max(periodNum - 4, 1)}` : "Suppl.";
}
return board === "basket" ? `Q${periodNum}` : `${periodNum}° tempo`;
}
return "—";
}
function updateRegiaSubtitle(periodLabel, board) {
if (!els.subtitle) return;
if (board === "basket" || board === "timed") {
els.subtitle.textContent = `Regia · ${periodLabel}`;
}
}
function applyScorePayload(data) {
const s = data.score;
if (!s) return;
@@ -109,8 +135,7 @@
const homeSets = s.home_sets ?? s.homeSets;
const awaySets = s.away_sets ?? s.awaySets;
const currentSet = s.current_set ?? s.currentSet;
const period = s.period;
const clockSecs = s.clock_secs ?? s.clockSecs ?? s.data?.clock_secs;
const periodLabel = resolvePeriodLabel(s, board);
const awayEl = document.getElementById("away-points");
const centerHint = document.getElementById("center-hint");
const clockLine = document.getElementById("clock-line");
@@ -119,11 +144,12 @@
if (awayEl) awayEl.textContent = awayPts;
if (board === "basket" || board === "timed") {
if (els.setsLine) els.setsLine.textContent = period || "—";
if (els.setsLine) els.setsLine.textContent = periodLabel;
if (els.scoreLine) els.scoreLine.textContent = `${cfg.homeName} ${homePts} - ${awayPts} ${cfg.awayName}`;
if (centerHint) centerHint.textContent = formatClock(clockSecs);
if (clockLine) clockLine.textContent = `Cronometro: ${formatClock(clockSecs)}`;
if (centerHint) centerHint.textContent = periodLabel;
updateRegiaSubtitle(periodLabel, board);
} else if (board === "timer") {
const clockSecs = s.clock_secs ?? s.clockSecs ?? s.data?.clock_secs;
if (els.setsLine) els.setsLine.textContent = "Cronometro";
if (clockLine) clockLine.textContent = formatClock(clockSecs, true);
} else if (board === "generic") {
@@ -184,11 +210,18 @@
async function handleAction(action) {
const prevHome = els.homePoints?.textContent;
const prevAway = document.getElementById("away-points")?.textContent;
const trigger = root.querySelector(`[data-action="${action}"]`);
if (trigger) trigger.disabled = true;
try {
const data = await postScore(action);
applyScorePayload(data);
setBadge(data);
if (action === "advance_period") {
const periodLabel = resolvePeriodLabel(data.score || {}, cfg.board);
toast(periodLabel === "—" ? "Periodo aggiornato" : `Ora in ${periodLabel}`);
}
if (cfg.board === "volley" || cfg.board === "racket") {
if (data.set_won && action !== "close_set") {
const winner = data.winner === "home" ? cfg.homeName : cfg.awayName;
@@ -204,6 +237,8 @@
const awayEl = document.getElementById("away-points");
if (prevAway != null && awayEl) awayEl.textContent = prevAway;
toast(e.message || "Errore");
} finally {
if (trigger) trigger.disabled = false;
}
}