mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
57ea219a43
This commit completes the reviewed Tours follow-up scope after the Tours MVP was merged into dev. Included feature blocks: - RC-01: identify Tours in PLAN day rows and show compact Tour facts; - RC-06: search for a city or address in TOUR-PLANNER without hidden writes; - RC-07: reorder Tour waypoints in the left sidebar; - RC-08: drag Tour waypoints on Leaflet, MapLibre and Mapbox with stable viewport, history and routing behavior; - RS-01: persist Tour descriptions and HTTPS information links with local provider classification; - RS-02: persist breaks/additional time and calculated or manually adjusted planned Tour duration without changing scheduling semantics. The implementation preserves: - ordinary Place and Legacy Track behavior; - Tours-off fallback behavior; - existing GPX/import behavior; - Tour assignment and deletion behavior; - calculated routing duration as a separate value; - existing Tour provenance fields; - keyboard/list alternatives for waypoint editing. Not included: - PR1-09 trip-wide Tour summary; - Wanderer integration; - GPX import changes; - new Tour types; - Tour-to-Day drag-and-drop; - further roadmap or Post-Release features. Validation: - focused RC-01/RC-06/RC-07/RC-08/RS-01/RS-02 tests passed; - affected shared/server/client typechecks passed; - migration and generated DB type checks passed; - scoped ESLint passed; - staged diff checks passed; - owner manual tests passed for all six feature blocks.
87 lines
3.2 KiB
TypeScript
87 lines
3.2 KiB
TypeScript
import type { TourListItem } from '@trek/shared'
|
|
import { tourWebsiteSchema } from '@trek/shared'
|
|
import { formatDurationShort } from '@trek/shared/roadtrip'
|
|
|
|
export type TourSource = 'trek' | 'gpx' | 'wanderer'
|
|
|
|
/** All / Unplanned / Planned, the same three states as the Places pool. */
|
|
export type TourFilter = 'all' | 'unplanned' | 'planned'
|
|
export interface TourWebsitePresentation {
|
|
href: string
|
|
domain: string
|
|
provider: 'Komoot' | 'AllTrails' | 'Outdooractive' | 'Wanderer' | null
|
|
}
|
|
|
|
export function formatPlannedTourDuration(minutes: number): string {
|
|
return formatDurationShort(minutes * 60)
|
|
}
|
|
|
|
export interface TourPlannedTimes {
|
|
walkingMinutes: number | null
|
|
breakMinutes: number | null
|
|
plannedTotalMinutes: number | null
|
|
manuallyOverridden: boolean
|
|
}
|
|
|
|
export function tourPlannedTimes(tour: Pick<TourListItem, 'duration' | 'planned_duration_minutes' | 'break_additional_minutes'>): TourPlannedTimes {
|
|
const manualOverride = tour.planned_duration_minutes ?? null
|
|
const breaks = tour.break_additional_minutes ?? 0
|
|
const plannedTotal = manualOverride ?? (tour.duration == null ? null : tour.duration + breaks)
|
|
return {
|
|
walkingMinutes: tour.duration,
|
|
breakMinutes: tour.break_additional_minutes ?? null,
|
|
plannedTotalMinutes: plannedTotal,
|
|
manuallyOverridden: manualOverride !== null,
|
|
}
|
|
}
|
|
|
|
const TOUR_WEBSITE_PROVIDERS = [
|
|
{ provider: 'Komoot', domains: ['komoot.com'] },
|
|
{ provider: 'AllTrails', domains: ['alltrails.com'] },
|
|
{ provider: 'Outdooractive', domains: ['outdooractive.com', 'outdooractive.de'] },
|
|
{ provider: 'Wanderer', domains: ['wanderer.to'] },
|
|
] as const
|
|
|
|
/** Classifies only the parsed host. It never resolves or requests the URL. */
|
|
export function tourWebsitePresentation(value: string | null | undefined): TourWebsitePresentation | null {
|
|
const parsed = tourWebsiteSchema.safeParse(value)
|
|
if (!parsed.success) return null
|
|
const hostname = new URL(parsed.data).hostname.toLowerCase().replace(/^www\./, '')
|
|
const match = TOUR_WEBSITE_PROVIDERS.find(({ domains }) =>
|
|
domains.some(domain => hostname === domain || hostname.endsWith(`.${domain}`))
|
|
)
|
|
return {
|
|
href: parsed.data,
|
|
domain: hostname,
|
|
provider: match?.provider ?? null,
|
|
}
|
|
}
|
|
|
|
type Translate = (key: string, params?: Record<string, unknown>) => string
|
|
|
|
/**
|
|
* Presentation-only source abstraction until provenance receives its own column.
|
|
* A wanderer reference is authoritative. Planner-authored TREK tours persist
|
|
* routing controls, while GPX imports intentionally remain geometry-only.
|
|
*/
|
|
export function tourSource(tour: Pick<TourListItem, 'wanderer_ref' | 'has_waypoints'>): TourSource {
|
|
if (tour.wanderer_ref) return 'wanderer'
|
|
return tour.has_waypoints === false ? 'gpx' : 'trek'
|
|
}
|
|
|
|
export function hikeSourceBadgeLabel(
|
|
tour: Pick<TourListItem, 'wanderer_ref' | 'has_waypoints'>,
|
|
t: Translate,
|
|
): string {
|
|
return t(`tours.badge.${tourSource(tour)}`)
|
|
}
|
|
|
|
/** The tours a list shows under the All / Unplanned / Planned filter, in their order. */
|
|
export function filterTours<T extends Pick<TourListItem, 'planned'>>(tours: T[], filter: TourFilter): T[] {
|
|
return tours.filter(tr => {
|
|
if (filter === 'unplanned') return !tr.planned
|
|
if (filter === 'planned') return tr.planned
|
|
return true
|
|
})
|
|
}
|