Files
TREK/client/src/components/Tours/tourDays.ts
T
Maurice 782e613506 Tours: day GPX import, wanderer trails and planning over an import
- GPX files drop onto the map or a day; the import lands on that day
- wanderer connection per user in Integrations; the workspace offers the
  user's own trails only, behind an admin switch under the Tours addon
- wanderer difficulty is stored on the SAC scale (T1 to T3), backfilled
- a GPX or wanderer import can be planned as an editable tour, either in
  place (the recorded track is kept and can be restored) or as a new tour
  that remembers the import it came from
- rails, rows and detail dialog follow the plan sidebar's cards and badges
- admin addon shelves with more than one row fold, collapsed by default
- reverse-geocoded waypoint names are cached on the device
2026-10-15 17:44:15 +02:00

37 lines
1.6 KiB
TypeScript

import { useMemo } from 'react';
import { useTripStore } from '../../store/tripStore';
import type { AssignmentsMap, Day } from '../../types';
import { formatDate } from '../../utils/formatters';
type Translate = (key: string, params?: Record<string, unknown>) => string;
export interface TourDay {
day: Day;
/** The day's position in the trip, so `index + 1` is the number the plan shows. */
index: number;
}
/**
* The days of the trip a tour is on, in the order of the trip and each once,
* read from the day lists themselves rather than from the tour list's
* `planned` flag, so a tour put on a day or taken off one shows it at once.
*/
export function tourDaysOf(placeId: number, days: readonly Day[], assignments: AssignmentsMap): TourDay[] {
return days.flatMap((day, index) =>
(assignments[String(day.id)] ?? []).some((assignment) => assignment.place_id === placeId) ? [{ day, index }] : []
);
}
/** `tourDaysOf` for one tour, following the store's day lists. */
export function useTourDays(placeId: number, days: readonly Day[]): TourDay[] {
const assignments = useTripStore((state) => state.assignments);
return useMemo(() => tourDaysOf(placeId, days, assignments ?? {}), [placeId, days, assignments]);
}
/** "Day 2, Tue, Jul 8: Lakes" as far as the day has a date and a title. */
export function dayMenuLabel(day: Day, index: number, t: Translate, locale: string): string {
const date = formatDate(day.date, locale);
const head = date ? `${t('dayplan.dayN', { n: index + 1 })}, ${date}` : t('dayplan.dayN', { n: index + 1 });
return day.title ? `${head}: ${day.title}` : head;
}