fix(tours): a city walk saved offline shows its stays and total at once, and the planner plans the total its overview shows (CW-02)

A city walk created or changed while offline now carries its stops, the
minutes its stays are entered with and how many have none yet, worked out
from its points the way the server will answer them. The day row, the tour
detail and the summary show the walking time with the stays as soon as the
walk is saved, with "at least" where a stay is missing, and a stay changed
while the write waits shows its new total rather than the one of the last
answer. The server and the client count the stops in one shared place.

The planner plans a walk whose walking time is not known yet with at least
the stays entered, as its overview says, so the planned field and the check
against the longest plan read the same total.

In the tour detail a longer time such as an "at least" total wraps on a
phone instead of being cut, and the boxes of a row keep one height. A total
entered by hand falls back to its short name where its column is too narrow.
This commit is contained in:
Maurice
2026-10-20 01:53:24 +00:00
parent fe78831bd9
commit 6bd19e2294
14 changed files with 196 additions and 44 deletions
@@ -1,7 +1,7 @@
import { Tours } from '../../db/entities/Tours.entity';
import type { ToursRepository, TourLibraryRow } from '../../db/repositories/Tours.repository';
import { TripMembershipService } from '../trip-membership/trip-membership.service';
import { parseRouteGeometry, thinnedLine, walkStationFacts } from './tours.helpers';
import { parseRouteGeometry, thinnedLine } from './tours.helpers';
import { ToursService } from './tours.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable, NotFoundException } from '@nestjs/common';
@@ -16,6 +16,7 @@ import {
type TourOrigin,
type TourTakeOverRequest,
type TourTypeKey,
walkStationFacts,
} from '@trek/shared';
/** The most rows one list reads before the name is matched; past it the answer says it was cut. */
+1 -22
View File
@@ -3,7 +3,7 @@
* PlacesService prepares and persists imported places; these helpers derive
* metrics from the resulting [[lat,lng,ele?]] geometry.
*/
import { walkStationsOf, type GeometryPoint, type TourListItem, type TourWaypoint } from '@trek/shared';
import type { GeometryPoint } from '@trek/shared';
import { createHash } from 'node:crypto';
@@ -30,27 +30,6 @@ export function parseRouteGeometry(routeGeometry: string | null | undefined): Ge
}
}
/** What a list says of a city walk's stations: how many, their stays as far as entered, and how many have none. */
export type WalkStationFacts = Pick<TourListItem, 'station_count' | 'station_stay_minutes' | 'station_stays_unknown'>;
/**
* CW-02, CW-03: a city walk's stations as a list counts them, from its saved
* points: a shaping point and the way back of a loop are no station, a stay
* nobody entered is counted apart and never as nothing. Any other type has none.
*/
export function walkStationFacts(
tourType: string,
points: readonly Pick<TourWaypoint, 'lat' | 'lng' | 'shaping' | 'stay_minutes'>[],
): WalkStationFacts {
if (tourType !== 'walk') return { station_count: null, station_stay_minutes: null, station_stays_unknown: null };
const stations = walkStationsOf(points);
return {
station_count: stations.length,
station_stay_minutes: stations.reduce((sum, station) => sum + (station.stay_minutes ?? 0), 0),
station_stays_unknown: stations.filter((station) => station.stay_minutes == null).length,
};
}
/** Confidence threshold: below this, the tour imports with a caution flag. */
export const LOW_CONFIDENCE_THRESHOLD = 0.5;
+1 -1
View File
@@ -33,7 +33,6 @@ import {
localHashOf,
parseRouteGeometry,
LOW_CONFIDENCE_THRESHOLD,
walkStationFacts,
type GeometryPoint,
} from './tours.helpers';
import { InjectRepository } from '@mikro-orm/nestjs';
@@ -58,6 +57,7 @@ import {
type TourProvenanceSource,
type TourWaypoint,
type WandererDifficulty,
walkStationFacts,
walkStationsOf,
wandererDifficultyToSac,
} from '@trek/shared';