feat(layouts): switch track layout mid-practice and view stats per layout
A club can run one Open Practice all season and re-lay the track now and then. Previously a session's layout was frozen at start and every training lap inherited it, so a season-long practice stayed on its first layout forever, and changing layout was hidden under Settings -> Appearance. - Each practice lap now counts toward the layout active when it was driven; a running practice session moves onto a new layout when one is added - "New layout" strip on Training stats, Race Day and the Dashboard, offered only around practice; a running race session blocks layout changes everywhere - "Stats for" selector (current / older layout / before layouts / all layouts) on Training stats and in the driver's mobile profile (?layout= on the public API) - A layout that has practice laps on it can no longer be deleted - Fix: the buildDriverTrainingStats wrapper in app.js dropped extra arguments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
196437d25b
commit
627179b95a
22 files changed
+454
-44
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// "Track layout: Layout 3 - since 12 Sep [New layout]" strip, shared by Training stats,
|
||||
// Race Day and the Dashboard. Changing layout is a practice-only action, so callers hide
|
||||
// the button while the session in focus is a race-format one; addTrackLayout additionally
|
||||
// refuses while any race session is running.
|
||||
import { getTrackLayoutIdAt, getTrackLayoutLabel, nextTrackLayoutLabel, normalizeTrackLayouts } from "./track_layouts_logic.js";
|
||||
|
||||
export function renderTrackLayoutBar({ state, t, escapeHtml, showNewButton = true }) {
|
||||
const layouts = normalizeTrackLayouts(state.trackLayouts);
|
||||
const currentId = getTrackLayoutIdAt(layouts);
|
||||
const current = layouts.find((layout) => layout.id === currentId);
|
||||
const text = current
|
||||
? t("layouts.bar_current", { label: getTrackLayoutLabel(layouts, currentId), date: new Date(current.startedAt).toLocaleDateString() })
|
||||
: t("layouts.bar_none");
|
||||
return `
|
||||
<div class="track-layout-bar" data-track-layout-bar>
|
||||
<span>${escapeHtml(text)}</span>
|
||||
${showNewButton ? `<button class="btn btn-mini" type="button" data-track-layout-new>${escapeHtml(t("layouts.new"))}</button>` : ""}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export function bindTrackLayoutBar(root, { state, t, addTrackLayout, renderView }) {
|
||||
root?.querySelectorAll("[data-track-layout-new]").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
const suggested = nextTrackLayoutLabel(normalizeTrackLayouts(state.trackLayouts));
|
||||
const label = window.prompt(t("layouts.new_prompt"), suggested);
|
||||
if (label === null) return;
|
||||
const result = addTrackLayout(label.trim() || suggested, Date.now());
|
||||
if (!result.ok) {
|
||||
window.alert(result.message);
|
||||
return;
|
||||
}
|
||||
renderView();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user