fix(series): report created races, delete a series with its races; group Race Day sessions by today's races (1.43.1)
This commit is contained in:
1 parent
74dbbf6ae0
commit
dbda06d101
10 files changed
+133
-13
No files matched your search
+33
-5
@@ -64,6 +64,33 @@ function renderQueueSession(session, positionKey, deps) {
|
||||
// count-down, and the check panel shows who has crossed the line since. The panel re-renders
|
||||
// on its own (refreshRaceDayWarmup) on every passing, without rebuilding the page.
|
||||
let lastWarmupDeps = null;
|
||||
let showAllSessions = false;
|
||||
|
||||
const localDateKey = (date = new Date()) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
||||
|
||||
// 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() }) {
|
||||
const eventById = new Map((events || []).map((event) => [event.id, event]));
|
||||
const isLive = (session) => ["running", "paused"].includes(session.status);
|
||||
const visible = (session) => {
|
||||
if (showAll || isLive(session) || session.id === selectedId) return true;
|
||||
const date = eventById.get(session.eventId)?.date;
|
||||
return date ? date === today : session.status === "ready";
|
||||
};
|
||||
const groups = new Map();
|
||||
let hidden = 0;
|
||||
(sessions || []).forEach((session) => {
|
||||
if (!visible(session)) { hidden += 1; return; }
|
||||
if (!groups.has(session.eventId)) groups.set(session.eventId, { event: eventById.get(session.eventId) || null, sessions: [] });
|
||||
groups.get(session.eventId).sessions.push(session);
|
||||
});
|
||||
const list = [...groups.values()].sort((a, b) =>
|
||||
Number(b.sessions.some(isLive)) - Number(a.sessions.some(isLive))
|
||||
|| String(b.event?.date || "").localeCompare(String(a.event?.date || "")));
|
||||
return { groups: list, hidden };
|
||||
}
|
||||
|
||||
function showsWarmupPanel(session) {
|
||||
return Boolean(session && session.status === "ready" && session.mode !== "track" && session.type !== "team_race" && !isPracticeSessionType(session.type));
|
||||
@@ -210,10 +237,7 @@ export function renderRaceDayView(deps) {
|
||||
const practiceLabel = !practice ? t("race_day.quick_practice_new")
|
||||
: practice.status === "running" ? t("race_day.quick_practice_show", { name: practice.name })
|
||||
: t("race_day.quick_practice_continue", { name: practice.name });
|
||||
const sessionChoices = state.sessions.slice().sort((a, b) => {
|
||||
const rank = (item) => (["running", "paused"].includes(item.status) ? 0 : item.status === "ready" ? 1 : 2);
|
||||
return rank(a) - rank(b) || Number(b.startedAt || 0) - Number(a.startedAt || 0);
|
||||
});
|
||||
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);
|
||||
// Layouts are a practice thing: never offered while a race session is in focus.
|
||||
@@ -248,9 +272,12 @@ export function renderRaceDayView(deps) {
|
||||
<label class="race-day-session-picker"><span>${t("race_day.pick_session")}</span>
|
||||
<select id="raceDaySessionSelect">
|
||||
${session ? "" : `<option value="">${t("race_day.none")}</option>`}
|
||||
${sessionChoices.map((item) => `<option value="${escapeHtml(item.id)}" ${session?.id === item.id ? "selected" : ""}>${escapeHtml(`${item.name} · ${getEventName(item.eventId)} · ${getStatusLabel(item.status)}`)}</option>`).join("")}
|
||||
${sessionChoices.groups.map((group) => `<optgroup label="${escapeHtml([group.event?.name || getEventName(group.sessions[0].eventId), group.event?.date].filter(Boolean).join(" · "))}">
|
||||
${group.sessions.map((item) => `<option value="${escapeHtml(item.id)}" ${session?.id === item.id ? "selected" : ""}>${escapeHtml(`${item.name} · ${getStatusLabel(item.status)}`)}</option>`).join("")}
|
||||
</optgroup>`).join("")}
|
||||
</select>
|
||||
</label>
|
||||
${sessionChoices.hidden || showAllSessions ? `<label class="race-day-show-all"><input type="checkbox" id="raceDayShowAllSessions" ${showAllSessions ? "checked" : ""} /> ${escapeHtml(t("race_day.show_all_sessions"))}${sessionChoices.hidden ? ` <span class="hint">${escapeHtml(t("race_day.hidden_sessions", { count: sessionChoices.hidden }))}</span>` : ""}</label>` : ""}
|
||||
${session && !isSelected ? `<button id="raceDayActivate" class="btn" type="button">${t("race_day.activate")}</button>` : ""}
|
||||
<div class="race-day-actions">
|
||||
${usesPrologue
|
||||
@@ -377,6 +404,7 @@ export function renderRaceDayView(deps) {
|
||||
});
|
||||
document.getElementById("raceDayQuickRace")?.addEventListener("click", () => navigateTo("race_setup"));
|
||||
document.getElementById("raceDaySessionSelect")?.addEventListener("change", (event) => { if (event.target.value) selectSession(event.target.value); });
|
||||
document.getElementById("raceDayShowAllSessions")?.addEventListener("change", (event) => { showAllSessions = event.target.checked; renderView(); });
|
||||
// Races: clear a heat's results (e.g. a restart after a false start) - not while it is running.
|
||||
document.getElementById("raceDayResetSession")?.addEventListener("click", () => {
|
||||
if (session && window.confirm(t("race_day.reset_session_confirm", { name: session.name }))) resetSessionData(session);
|
||||
|
||||
Reference in new issue
Block a user