Each layout can carry its own lap window (set on creation, editable in Settings, saved from Race Day during practice). Open/Free practice on that layout uses it; races always keep the event's values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
2.0 KiB
JavaScript
38 lines
2.0 KiB
JavaScript
// "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;
|
|
// Optional: a rebuilt track often needs its own minimum lap time (empty = the event's).
|
|
const minLapSec = Number(String(window.prompt(t("layouts.new_min_lap_prompt"), "") || "").replace(",", "."));
|
|
const result = addTrackLayout(label.trim() || suggested, Date.now(), { minLapMs: Number.isFinite(minLapSec) && minLapSec > 0 ? Math.round(minLapSec * 1000) : 0 });
|
|
if (!result.ok) {
|
|
window.alert(result.message);
|
|
return;
|
|
}
|
|
renderView();
|
|
});
|
|
});
|
|
}
|