aboutsummaryrefslogtreecommitdiff
path: root/web/frontend/ride-detail-boundaries.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/frontend/ride-detail-boundaries.ts')
-rw-r--r--web/frontend/ride-detail-boundaries.ts26
1 files changed, 23 insertions, 3 deletions
diff --git a/web/frontend/ride-detail-boundaries.ts b/web/frontend/ride-detail-boundaries.ts
index a9bb8e1..f1d80e7 100644
--- a/web/frontend/ride-detail-boundaries.ts
+++ b/web/frontend/ride-detail-boundaries.ts
@@ -1,4 +1,4 @@
-import { climbMetrics, formatDistance, formatElevation } from "./ride-detail-logic.js";
+import { climbMetrics, climbSample, formatDistance, formatElevation } from "./ride-detail-logic.js";
import { requireElement } from "./dom.js";
import type { BoundarySource, BoundaryTarget, ClimbBounds, RideProfilePoint } from "./types.js";
@@ -104,11 +104,13 @@ export class RideBoundaryController {
const item = form.closest<HTMLElement>("[data-climb-item]");
if (!item) return;
const climbIndex = Number.parseInt(item.dataset.climbIndex ?? "", 10);
- const metrics = climbMetrics(this.points, this.climbBounds[climbIndex]);
- if (!metrics) {
+ const bounds = this.climbBounds[climbIndex];
+ const metrics = climbMetrics(this.points, bounds);
+ if (!bounds || !metrics) {
preview.textContent = "Choose an end point after the start point.";
return;
}
+ this.syncSnapshot(form, bounds);
const summary = requireElement(item.querySelector<HTMLElement>("[data-climb-summary]"), "climb summary");
const metricsOutput = requireElement(item.querySelector<HTMLElement>("[data-climb-metrics]"), "climb metrics");
summary.textContent = `${formatDistance(metrics.start.distanceKm)}–${formatDistance(metrics.end.distanceKm)}`;
@@ -116,6 +118,24 @@ export class RideBoundaryController {
preview.textContent = `Preview: ${formatDistance(metrics.distanceKm)} · ${metrics.elevationGain >= 0 ? "+" : ""}${formatElevation(metrics.elevationGain)} · ${metrics.slope.toFixed(1)}% · Cotacol ${metrics.cotacol.toFixed(1)}`;
}
+ // syncSnapshot fills the fields the preview save posts: the preview ride is never persisted.
+ syncSnapshot(form: HTMLFormElement, bounds: ClimbBounds): void {
+ const sample = climbSample(this.points, bounds);
+ if (!sample) return;
+ const snapshot: Array<[string, number]> = [
+ ["start_lat", this.points[bounds.startIndex].latitude],
+ ["start_lon", this.points[bounds.startIndex].longitude],
+ ["end_lat", this.points[bounds.endIndex].latitude],
+ ["end_lon", this.points[bounds.endIndex].longitude],
+ ["sample_distance_m", sample.distanceM],
+ ["sample_elevation_gain_m", sample.elevationGainM],
+ ];
+ for (const [name, value] of snapshot) {
+ const input = form.querySelector<HTMLInputElement>(`input[name="${name}"]`);
+ if (input) input.value = String(value);
+ }
+ }
+
boundaryLabel(index: number): string {
const point = this.points[index];
const idx = point.index ?? index;