fix(profile): open the mobile profile on the class driven last (1.42.3)
Passes and exercises only count the selected class, and the profile opened on the first registered one, so laps with another car never showed. It now opens on the class with the latest lap and offers a switch when today's latest laps are in another class.
This commit is contained in:
1 parent
3eb4b5f042
commit
ca88fd9ecc
9 files changed
+99
-4
No files matched your search
@@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm
|
||||
|
||||
No changes recorded yet.
|
||||
|
||||
## 1.42.3 - 2026-10-25
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Mobile profile with several classes showed no laps in a pass.** A driver with one car per class (e.g. 2WD, 4WD, Truck) got the profile opened on the first registered class, while a practice pass, Even laps and Step training only count the selected class - so laps driven with the 4WD never showed up. The profile now opens on the class driven last, and when today's latest laps are in another class than the selected one it says so with a **Switch to …** button.
|
||||
|
||||
## 1.42.2 - 2026-10-23
|
||||
|
||||
### Fixed
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.42.2",
|
||||
"version": "1.42.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rc-racecore",
|
||||
"version": "1.42.2",
|
||||
"version": "1.42.3",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^12.11.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.42.2",
|
||||
"version": "1.42.3",
|
||||
"private": true,
|
||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||
"engines": {
|
||||
|
||||
@@ -161,6 +161,8 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
|
||||
return {
|
||||
classId,
|
||||
className: String(classes.find((item) => String(item?.id || "") === classId)?.name || "").trim(),
|
||||
// The phone opens on the class driven last and points out a switch (see public_training.js).
|
||||
lastLapAt: classLaps.length ? classLaps[classLaps.length - 1].timestamp : 0,
|
||||
brand: brands.join(" / "),
|
||||
stats: filterPublicTrainingStats(stats, visibility),
|
||||
channelStats: visibility.performance ? channelStats : {},
|
||||
|
||||
@@ -1505,3 +1505,16 @@ button {
|
||||
.public-training-connection[data-state="failed"], .public-training-connection[data-state="stale"] { color: var(--gold); }
|
||||
.public-training-connection button { flex-shrink: 0; padding: 6px 10px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
|
||||
.public-training-connection button[hidden] { display: none; }
|
||||
|
||||
/* "Your latest laps today are in 4WD" - the pass and exercises only count the selected class. */
|
||||
.profile-class-switch {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
margin: 12px 0 0;
|
||||
padding: 10px 12px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(245, 166, 35, 0.6);
|
||||
background: rgba(245, 166, 35, 0.12);
|
||||
}
|
||||
+18
-1
@@ -23,6 +23,8 @@ const messages = {
|
||||
loadError: "Kunde inte läsa träningsprofilen. Länken kan vara avstängd eller ersatt.",
|
||||
development: "Förarutveckling",
|
||||
class: "Klass",
|
||||
drivingOtherClass: "Dina senaste varv i dag är i {className}. Passet och övningarna räknar bara vald klass.",
|
||||
switchClass: "Byt till {className}",
|
||||
layoutStats: "Banlayout",
|
||||
lapSource: "Underlag",
|
||||
lapSourcePractice: "Träning",
|
||||
@@ -197,6 +199,8 @@ const messages = {
|
||||
loadError: "The training profile could not be loaded. The link may be disabled or replaced.",
|
||||
development: "Driver development",
|
||||
class: "Class",
|
||||
drivingOtherClass: "Your latest laps today are in {className}. The pass and the exercises only count the selected class.",
|
||||
switchClass: "Switch to {className}",
|
||||
layoutStats: "Track layout",
|
||||
lapSource: "Based on",
|
||||
lapSourcePractice: "Practice",
|
||||
@@ -530,8 +534,14 @@ function renderProfile(data) {
|
||||
const { profile, branding } = data;
|
||||
const visibility = { progress: true, achievements: true, performance: true, goals: true, history: true, ...(data.visibility || {}) };
|
||||
const classProfiles = Array.isArray(data.classProfiles) ? data.classProfiles : [];
|
||||
let activeClass = classProfiles.find((item) => String(item.classId || "") === selectedClassId) || classProfiles[0] || null;
|
||||
// A driver with several classes (one car each): open on the class driven last, not the first
|
||||
// registered one - a practice pass, Even laps and Step training only count the selected class,
|
||||
// so the wrong one showed no laps at all.
|
||||
const lastDrivenClass = classProfiles.reduce((latest, item) => (Number(item.lastLapAt || 0) > Number(latest?.lastLapAt || 0) ? item : latest), null);
|
||||
let activeClass = classProfiles.find((item) => String(item.classId || "") === selectedClassId) || lastDrivenClass || classProfiles[0] || null;
|
||||
if (activeClass && selectedClassId !== activeClass.classId) selectedClassId = activeClass.classId;
|
||||
const drivingOtherClass = lastDrivenClass && activeClass && lastDrivenClass.classId !== activeClass.classId
|
||||
&& getLocalDayKey(lastDrivenClass.lastLapAt) === getLocalDayKey(Date.now()) ? lastDrivenClass : null;
|
||||
const stats = { dailySummaries: [], paceHistory: [], achievements: [], stintSummaries: [], ...(activeClass?.stats || data.stats || {}) };
|
||||
const channelStats = activeClass?.channelStats || data.channelStats || {};
|
||||
const nextMilestone = activeClass?.nextMilestone || data.nextMilestone;
|
||||
@@ -658,6 +668,7 @@ function renderProfile(data) {
|
||||
${renderLayoutSelect(data.trackLayouts)}
|
||||
${renderSourceSelect(data.lapSource)}
|
||||
</div>
|
||||
${drivingOtherClass ? `<p class="profile-class-switch">${escapeHtml(t("drivingOtherClass", { className: drivingOtherClass.className || drivingOtherClass.classId }))} <button type="button" class="profile-button" data-switch-class="${escapeHtml(drivingOtherClass.classId)}">${escapeHtml(t("switchClass", { className: drivingOtherClass.className || drivingOtherClass.classId }))}</button></p>` : ""}
|
||||
</section>
|
||||
|
||||
<section class="profile-stat-grid">
|
||||
@@ -960,6 +971,12 @@ function renderProfile(data) {
|
||||
window.history.replaceState({}, "", nextUrl);
|
||||
loadProfile();
|
||||
});
|
||||
root.querySelector("[data-switch-class]")?.addEventListener("click", (event) => {
|
||||
const select = document.getElementById("profileClass");
|
||||
if (!(select instanceof HTMLSelectElement)) return;
|
||||
select.value = String(event.currentTarget.dataset.switchClass || "");
|
||||
select.dispatchEvent(new Event("change"));
|
||||
});
|
||||
document.getElementById("profileClass")?.addEventListener("change", (event) => {
|
||||
selectedClassId = String(event.currentTarget.value || "");
|
||||
const nextUrl = new URL(window.location.href);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
// A driver with several classes (one car each) went out with the 4WD, started a pass on the
|
||||
// phone and saw no laps: the profile opened on the first registered class, and passes and
|
||||
// exercises only count the selected class. It now opens on the class driven last, and points
|
||||
// out a switch when the latest laps today are in another class.
|
||||
export async function runProfileClassSmoke({ evaluate, savedState, waitFor, base, send }) {
|
||||
const seeded = await savedState();
|
||||
const token = "browser-profile-class-token-123456789012";
|
||||
const now = Date.now();
|
||||
const lap = (driverId, minutesAgo, lapMs) => ({ id: `pc_${driverId}_${minutesAgo}`, sourceKey: `pc_${driverId}_${minutesAgo}`, driverId, sessionId: "pc_session", timestamp: now - minutesAgo * 60000, lapMs });
|
||||
const state = {
|
||||
...seeded,
|
||||
classes: [...seeded.classes, { id: "pc_2wd", name: "PC 2WD" }, { id: "pc_4wd", name: "PC 4WD" }, { id: "pc_truck", name: "PC Truck" }],
|
||||
drivers: [...seeded.drivers,
|
||||
{ id: "pc_driver_2wd", profileId: "pc_profile", name: "PC Driver", classId: "pc_2wd" },
|
||||
{ id: "pc_driver_4wd", profileId: "pc_profile", name: "PC Driver", classId: "pc_4wd" },
|
||||
{ id: "pc_driver_truck", profileId: "pc_profile", name: "PC Driver", classId: "pc_truck" }],
|
||||
training: {
|
||||
...(seeded.training || {}),
|
||||
shares: [...(seeded.training?.shares || []), { driverId: "pc_driver_2wd", token, enabled: true }],
|
||||
ledger: [...(seeded.training?.ledger || []), lap("pc_driver_2wd", 300, 20000), lap("pc_driver_2wd", 299, 19800), lap("pc_driver_4wd", 3, 17000), lap("pc_driver_4wd", 2, 16800)],
|
||||
},
|
||||
};
|
||||
const response = await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(state) });
|
||||
assert.equal(response.ok, true);
|
||||
const selectedClass = () => evaluate(`document.getElementById("profileClass")?.value`);
|
||||
|
||||
await send("Page.navigate", { url: `${base}/public-training/${token}?lang=en` });
|
||||
await waitFor(async () => (await selectedClass()) === "pc_4wd", "the profile opens on the 4WD, the class driven last");
|
||||
assert.equal(await evaluate(`Boolean(document.querySelector("[data-switch-class]"))`), false, "no switch hint when the right class is shown");
|
||||
console.log("PASS the mobile profile opens on the class driven last, not the first registered one");
|
||||
|
||||
await send("Page.navigate", { url: `${base}/public-training/${token}?lang=en&class=pc_2wd` });
|
||||
await waitFor(async () => Boolean(await evaluate(`document.querySelector("[data-switch-class]")`)), "switch hint shown on another class");
|
||||
assert.match(await evaluate(`document.querySelector(".profile-class-switch").innerText`), /PC 4WD/);
|
||||
await evaluate(`document.querySelector("[data-switch-class]").click()`);
|
||||
await waitFor(async () => (await selectedClass()) === "pc_4wd", "the button switches to the 4WD");
|
||||
assert.match(await evaluate(`location.search`), /class=pc_4wd/);
|
||||
assert.equal(await evaluate(`Boolean(document.querySelector("[data-switch-class]"))`), false);
|
||||
console.log("PASS on another class, the profile says the latest laps are in the 4WD and switches in one tap");
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { runPrologueSmoke } from "./browser_prologue.js";
|
||||
import { runPracticeResetSmoke } from "./browser_practice_reset.js";
|
||||
import { runSuspectLapsSmoke } from "./browser_suspect_laps.js";
|
||||
import { runOverlayDriverLinkSmoke } from "./browser_overlay_driver_link.js";
|
||||
import { runProfileClassSmoke } from "./browser_profile_class.js";
|
||||
import { runCorrectionsScopeSmoke } from "./browser_corrections_scope.js";
|
||||
import { runDriversPageSmoke } from "./browser_drivers_page.js";
|
||||
import { runSeriesSmoke } from "./browser_series.js";
|
||||
@@ -217,6 +218,7 @@ try {
|
||||
await evaluate('document.getElementById("publicTrainingRetry").click()');
|
||||
await waitFor(async () => await evaluate('document.getElementById("publicTrainingConnection")?.dataset.state === "current"'), "mobile retry recovered");
|
||||
console.log("PASS mobile offline status preserves profile nodes and retry recovers");
|
||||
await runProfileClassSmoke({ evaluate, savedState, waitFor, base, send });
|
||||
assert.deepEqual(errors, []);
|
||||
if (dialogs.length) console.log("NOTE auto-accepted native dialog(s):", JSON.stringify(dialogs));
|
||||
console.log("PASS offline save failure, local draft retention, retry and confirmed saved status");
|
||||
|
||||
@@ -507,3 +507,16 @@ test("public profile counts practice by default; race laps only with source race
|
||||
assert.equal(stats("all").totalLaps, 6);
|
||||
assert.equal(buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, "", 0, 0, 0, 0, "current", "bogus").lapSource, "practice");
|
||||
});
|
||||
|
||||
test("each class in a mobile profile carries the time of its latest lap, so the phone opens on the class driven last", () => {
|
||||
const now = Date.now();
|
||||
const state = buildState(now);
|
||||
let profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, new Date(now).toISOString());
|
||||
const lastLapAt = (classId) => profile.classProfiles.find((item) => item.classId === classId).lastLapAt;
|
||||
assert.equal(lastLapAt("class_1"), now - 4000, "2WD: the 0.5 s non-lap is not a lap");
|
||||
assert.equal(lastLapAt("class_2"), now - 5000);
|
||||
// Out with the 4WD now: it becomes the class driven last.
|
||||
state.training.ledger.push({ driverId: "driver_1_4wd", sessionId: "free", timestamp: now - 1000, lapMs: 14200 });
|
||||
profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, new Date(now).toISOString());
|
||||
assert.equal(lastLapAt("class_2"), now - 1000);
|
||||
});
|
||||
Reference in new issue
Block a user