fix(race-day): reset a heat to ready with its clock at zero, keep recent races listed (1.45.2)

This commit is contained in:
larssand committed 2026-11-01 10:49:17 +01:00
1 parent 7376595001
commit ab1c26a89b
7 files changed
+62 -14

No files matched your search

+14 -4
View File
@@ -357,11 +357,21 @@ function resetSessionData(session) {
session.resultsResetAt = Date.now();
delete state.resultsBySession[session.id];
session.followUpStartedAt = null;
// A heat (anything but an Open/Free Practice that runs all evening) goes back to "ready":
// the clock is back at zero and it can be started again.
const rerunHeat = !isPracticeSessionType(session.type) && session.status !== "running";
if (rerunHeat) {
// An empty result, also written straight to the server: a plain delete was put back by
// the server's live-results protection when the reset came right after the last lap.
ensureSessionResult(session.id);
Object.assign(session, { status: "ready", startedAt: null, endedAt: null, finishedByTimer: false, pausedAt: null, totalPausedMs: 0, followUpPausedMs: 0, audioAnnouncements: [] });
}
lastFinishAnnouncementSessionId = null;
delete lastOverlayLeaderKeyBySession[session.id];
delete lastOverlayTop3BySession[session.id];
overlayEvents = [];
saveState();
if (rerunHeat) void persistSessionResultToBackend(session.id);
renderView();
return true;
}
@@ -953,8 +963,8 @@ const TRANSLATIONS = {
"race_day.show_all_sessions": "Visa alla sessioner",
"race_day.go_next": "Nästa: {name}",
"race_day.hidden_sessions": "({count} från andra dagar dolda)",
"race_day.reset_session_hint": "Nollställer sessionens varv och resultat, t.ex. vid omstart. Pausa först om heatet körs.",
"race_day.reset_session_confirm": "Nollställ alla varv och resultat i \"{name}\"?\n\nDet går inte att ångra.",
"race_day.reset_session_hint": "Nollställer sessionens varv, resultat och klocka så att den kan köras om. Pausa först om heatet körs.",
"race_day.reset_session_confirm": "Nollställ alla varv och resultat i \"{name}\" och ställ klockan på noll så att den kan startas om?\n\nDet går inte att ångra.",
"race_day.new_practice_day": "Nollställ – ny träningsdag",
"race_day.new_practice_day_hint": "Nollställer dagens varv i tidtagningen. Alla varv finns kvar i träningsstatistiken.",
"race_day.new_practice_day_confirm": "Starta en ny träningsdag i \"{name}\"?\n\nDagens varv nollställs i tidtagningen (topplistan börjar om). Alla varv finns kvar i träningsstatistiken.",
@@ -2822,8 +2832,8 @@ const TRANSLATIONS = {
"race_day.show_all_sessions": "Show all sessions",
"race_day.go_next": "Next: {name}",
"race_day.hidden_sessions": "({count} from other days hidden)",
"race_day.reset_session_hint": "Clears the session's laps and results, e.g. for a restart. Pause first if the heat is running.",
"race_day.reset_session_confirm": "Clear every lap and result in \"{name}\"?\n\nThis cannot be undone.",
"race_day.reset_session_hint": "Clears the session's laps, results and clock so it can be run again. Pause first if the heat is running.",
"race_day.reset_session_confirm": "Clear every lap and result in \"{name}\" and set its clock back to zero so it can be started again?\n\nThis cannot be undone.",
"race_day.new_practice_day": "Reset – new practice day",
"race_day.new_practice_day_hint": "Clears today's laps in timing. Every lap stays in the training statistics.",
"race_day.new_practice_day_confirm": "Start a new practice day in \"{name}\"?\n\nToday's laps are cleared in timing (the leaderboard starts over). Every lap stays in the training statistics.",
+11 -5
View File
@@ -70,14 +70,17 @@ const localDateKey = (date = new Date()) => `${date.getFullYear()}-${String(date
// The session picker lists today's races by default (plus whatever is live or selected),
// grouped per race in the order they were set up. Old races, practices and other series'
// rounds stay out of the way until "Show all" is ticked. Undated races show unrun sessions.
export function buildRaceDaySessionGroups({ sessions, events, selectedId = "", showAll = false, today = localDateKey() }) {
// rounds stay out of the way until "Show all" is ticked.
export function buildRaceDaySessionGroups({ sessions, events, selectedId = "", showAll = false, today = localDateKey(), now = Date.now() }) {
const eventById = new Map((events || []).map((event) => [event.id, event]));
const isLive = (session) => ["running", "paused"].includes(session.status);
// A race is "today's" by its date, or when something in it ran in the last 12 hours (a
// race day going past midnight, a date set wrong). Undated races are always listed.
const recentEventIds = new Set((sessions || []).filter((session) => Number(session.startedAt) > now - 12 * 3600 * 1000).map((session) => session.eventId));
const visible = (session) => {
if (showAll || isLive(session) || session.id === selectedId) return true;
if (showAll || isLive(session) || session.id === selectedId || recentEventIds.has(session.eventId)) return true;
const date = eventById.get(session.eventId)?.date;
return date ? date === today : session.status === "ready";
return !date || date === today;
};
const groups = new Map();
let hidden = 0;
@@ -240,6 +243,9 @@ export function renderRaceDayView(deps) {
const sessionChoices = buildRaceDaySessionGroups({ sessions: state.sessions, events: state.events, selectedId: session?.id, showAll: showAllSessions });
const isPracticeSession = Boolean(session && (isPracticeSessionType(session.type) || session.type === "practice"));
const isLiveSession = ["running", "paused"].includes(session?.status);
// Open/Free Practice runs all evening and is reset per day; a race's practice (seeding) is
// reset like a heat.
const isOpenPractice = Boolean(session && isPracticeSessionType(session.type));
// Layouts are a practice thing: never offered while a race session is in focus.
const layoutAllowed = !session || isPracticeSessionType(session.type);
dom.view.innerHTML = `
@@ -289,7 +295,7 @@ export function renderRaceDayView(deps) {
${session?.status === "running" ? `<button id="raceDayPause" class="btn btn-danger" type="button">⏸ ${t(isPracticeSession ? "race_day.pause_practice" : "audio.race_pause")}</button>` : ""}
${session?.status === "paused" ? `<button id="raceDayResume" class="btn btn-go" type="button">${t(isPracticeSession ? "race_day.resume_practice" : "audio.race_resume")}</button>` : ""}
${isLiveSession ? `<button id="raceDayFinish" class="btn btn-checkered" type="button">🏁 ${t(isPracticeSession ? "race_day.finish_practice" : "race_day.finish")}</button>` : ""}
${isPracticeSession ? `<button id="raceDayNewPracticeDay" class="btn" type="button" title="${escapeHtml(t("race_day.new_practice_day_hint"))}">${t("race_day.new_practice_day")}</button>`
${isOpenPractice ? `<button id="raceDayNewPracticeDay" class="btn" type="button" title="${escapeHtml(t("race_day.new_practice_day_hint"))}">${t("race_day.new_practice_day")}</button>`
: session && session.status !== "running" ? `<button id="raceDayResetSession" class="btn" type="button" title="${escapeHtml(t("race_day.reset_session_hint"))}">${t("timing.reset")}</button>` : ""}`}
</div>
${isPracticeSession ? "" : `<div id="raceDayStartLights" class="race-start-lights" data-state="${escapeHtml(getStartLightState())}">