Files
TREK/client/src/components/Tours/tourShareText.ts
T
Maurice 31859651d7 feat(help): rewrite the help center for v5 with a Tours section, new pictures in every language, and fix the tour planner bugs it surfaced
Every help screen checked against the v5 redesign. Tours is documented for
the first time, as a screen of its own with twelve screens under it, and
notifications get help of their own. All pictures are taken again on a
realistic demo trip, with short loops where a still cannot show the motion.
The English is plain and every language is written naturally rather than
word for word.

The switcher shows two levels at most, a screen's overview lists its
sub-screens as cards above its guides, each wiki page is linked once, and
the help sidebar is wider.

Fixes found along the way: Save to Collection keeps a tour's route, a track
dropped on the places column opens the Tours import, tour Share on desktop,
the unsaved tour draft lives on the account, a route click no longer adds
an end point, Trip places leaves the trip's tours out, Escape closes a
stage's day menu, confirms before destructive deletes, DWD warnings sharing
one id kept apart, a booking's date moves with it, and smaller fixes across
notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and
the admin screens.
2026-10-22 22:29:35 +02:00

83 lines
3.2 KiB
TypeScript

import type { TourListItem } from '@trek/shared';
import type { DistanceUnit } from '../../types';
import { formatDistance, formatElevation } from '../../utils/units';
import type { Translate } from './tourDayTimeHint';
import { heightsUnknown } from './tourFacts';
import { formatPlannedTourDuration, tourPlannedTimes } from './tourPresentation';
/**
* What a tour's short share text says about it, as the card's head shows it:
* the type, the distance, the ascent and the time. Unknown values are null and
* left out of the text.
*/
export interface TourShareFacts {
tourType: TourListItem['tour_type'];
distanceKm: number | null;
gain: number | null;
minutes: number | null;
}
/** The facts of a saved tour, measured from its line where there is one, like the card's head. */
export function tourShareFactsOf(
tour: TourListItem,
analysis: { distanceKm: number; gain: number | null } | null
): TourShareFacts {
const times = tourPlannedTimes(tour);
const gain = analysis ? analysis.gain : tour.elevation_gain;
return {
tourType: tour.tour_type,
distanceKm: analysis?.distanceKm ?? tour.distance,
// A paddle tour's heights are read off the banks, not the water: they stay unknown.
gain: heightsUnknown(tour) ? null : gain,
minutes: times.plannedTotalMinutes ?? times.walkingMinutes,
};
}
/** What the planner knows of the tour it edits, measured from its line as it is now. */
interface PlannerShareSource {
tourType: TourShareFacts['tourType'];
isPaddle: boolean;
routeAnalysis: { distanceKm: number; gain: number | null } | null;
plannedTotalMinutes: number | null;
walkingDurationMinutes: number | null;
}
/** The facts of the tour open in the planner, like its rail shows them. */
export function plannerShareFacts(planner: PlannerShareSource): TourShareFacts {
return {
tourType: planner.tourType,
distanceKm: planner.routeAnalysis?.distanceKm ?? null,
// A paddle tour's heights stay unknown here too.
gain: planner.isPaddle ? null : (planner.routeAnalysis?.gain ?? null),
minutes: planner.plannedTotalMinutes ?? planner.walkingDurationMinutes,
};
}
/** What the share text is made of: the tour's name, its facts where known, the trip's name. */
interface TourShareTextInput {
name: string;
facts: TourShareFacts | null;
tripName: string | null;
}
/**
* The tour as a few lines of plain text, for a browser that cannot hand the GPX
* file on: its name, type, distance, ascent, time and the trip it belongs to.
*/
export function tourShareText({ name, facts, tripName }: TourShareTextInput, t: Translate, unit: DistanceUnit): string {
const lines = [name.trim() || null];
if (facts) {
lines.push(t(`tourTypes.${facts.tourType}`));
if (facts.distanceKm != null) {
lines.push(`${t('tours.detail.distance')}: ${formatDistance(facts.distanceKm, unit)}`);
}
if (facts.gain != null) lines.push(`${t('tours.detail.ascent')}: ${formatElevation(facts.gain, unit)}`);
if (facts.minutes != null) {
lines.push(t('tours.gpxExport.shareDuration', { time: formatPlannedTourDuration(facts.minutes) }));
}
}
const trip = tripName?.trim();
if (trip) lines.push(t('tours.gpxExport.shareTrip', { name: trip }));
return lines.filter((line): line is string => !!line).join('\n');
}