Skip to content

Commit cc6e531

Browse files
committed
plan: rerender immediately after session add/remove actions
1 parent 48d6d31 commit cc6e531

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

static/plan.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,20 @@
11181118
return true;
11191119
}
11201120

1121+
async function rerenderRowsAfterSessionShapeChange(dateValue, sessionIndex = 0) {
1122+
await renderRows(renderedRows);
1123+
const dateKey = String(dateValue || "").trim();
1124+
if (!isIsoDateString(dateKey)) return;
1125+
const targetIndex = Math.max(0, Number.parseInt(String(sessionIndex || 0), 10) || 0);
1126+
const selector = `.plan-session-distance[data-date="${dateKey}"][data-session-index="${targetIndex}"]`;
1127+
const target = bodyEl.querySelector(selector) || bodyEl.querySelector(distanceSelectorForDate(dateKey));
1128+
if (!(target instanceof HTMLInputElement)) return;
1129+
target.focus();
1130+
if (typeof target.select === "function") {
1131+
target.select();
1132+
}
1133+
}
1134+
11211135
function buildSessionTypeSelect(row, index, rows, session, sessionIndex) {
11221136
const select = document.createElement("select");
11231137
select.className = "plan-run-type plan-session-type";
@@ -1254,6 +1268,7 @@
12541268
const current = collectSessionPayloadForDate(row.date);
12551269
current.push({ ordinal: current.length + 1, planned_miles: 1.0, run_type: "", planned_workout: "" });
12561270
saveSessionPayload(row, index, rows, row.date, current, { preserveFocus: true });
1271+
void rerenderRowsAfterSessionShapeChange(row.date, Math.max(0, current.length - 1));
12571272
});
12581273
inlineActions.appendChild(addBtn);
12591274

@@ -1267,6 +1282,7 @@
12671282
const current = collectSessionPayloadForDate(row.date);
12681283
if (current.length > 0) current.pop();
12691284
saveSessionPayload(row, index, rows, row.date, current, { preserveFocus: true });
1285+
void rerenderRowsAfterSessionShapeChange(row.date, Math.max(0, current.length - 1));
12701286
});
12711287
inlineActions.appendChild(removeBtn);
12721288

0 commit comments

Comments
 (0)