diff --git a/client/src/components/Planner/stopNumbers.test.ts b/client/src/components/Planner/stopNumbers.test.ts new file mode 100644 index 000000000..ec9d22a62 --- /dev/null +++ b/client/src/components/Planner/stopNumbers.test.ts @@ -0,0 +1,27 @@ +// FE-PLANNER-STOPNUM-001 to -002: the one stop count the map's pins and the plan's rows read (#2584). +import { describe, expect, it } from 'vitest'; + +import type { Assignment } from '../../types'; +import { stopNumbersOfDay } from './stopNumbers'; + +const stop = (id: number, order_index: number, place: Partial> | null = {}) => + ({ id, order_index, place: place && { id: id * 10, ...place } }) as unknown as Assignment; + +describe('stopNumbersOfDay', () => { + it('FE-PLANNER-STOPNUM-001: numbers the stops from 1 in their stored order', () => { + const numbers = stopNumbersOfDay([stop(3, 2), stop(1, 0), stop(2, 1)]); + expect([...numbers.entries()]).toEqual([ + [1, 1], + [2, 2], + [3, 3], + ]); + }); + + it('FE-PLANNER-STOPNUM-002: passes over service stops and rows without a place', () => { + const numbers = stopNumbersOfDay([stop(1, 0), stop(2, 1, { stop_type: 'fuel' }), stop(3, 2, null), stop(4, 3)]); + expect(numbers.get(1)).toBe(1); + expect(numbers.has(2)).toBe(false); + expect(numbers.has(3)).toBe(false); + expect(numbers.get(4)).toBe(2); + }); +}); diff --git a/client/src/components/Planner/stopNumbers.ts b/client/src/components/Planner/stopNumbers.ts new file mode 100644 index 000000000..b14e2f009 --- /dev/null +++ b/client/src/components/Planner/stopNumbers.ts @@ -0,0 +1,22 @@ +import type { Assignment } from '../../types'; +import { isServiceStopType } from '../Roadtrip/roadtripModel'; + +/** + * The number each stop of a day carries, by assignment id: counted from 1 in the + * day's stored order. A service stop is passed over rather than counted: the map + * draws it without a badge and the rail gives it no number, so a number spent on + * it left the pin after a fuel stop wearing "3" where the rail said "2". + * + * The one count the map's pins and the plan's rows both read (#2584), so the + * number beside a stop in the list is the one on its pin. + */ +export function stopNumbersOfDay(dayAssignments: readonly Assignment[]): Map { + const numbers = new Map(); + let counted = 0; + for (const a of [...dayAssignments].sort((x, y) => x.order_index - y.order_index)) { + if (!a.place?.id || isServiceStopType(a.place.stop_type)) continue; + counted += 1; + numbers.set(a.id, counted); + } + return numbers; +} diff --git a/client/src/mobile/mobile.css b/client/src/mobile/mobile.css index 0437d70e3..311d76ef1 100644 --- a/client/src/mobile/mobile.css +++ b/client/src/mobile/mobile.css @@ -925,3 +925,23 @@ html:has(.m-shell) ::-webkit-scrollbar { grid-template-columns: repeat(2, minmax(0, 1fr)); } } + +/* A stop's number in the plan, as its pin on the map carries it (#2584): + at the foot of its picture, on the trailing side. */ +.m-root .m-stop-num { + position: absolute; + inset-inline-end: -4px; + bottom: -3px; + display: grid; + place-items: center; + min-width: 16px; + height: 16px; + padding-inline: 4px; + border-radius: 999px; + background: var(--m-act); + color: var(--m-actfg); + box-shadow: 0 0 0 1.5px var(--m-bg); + font: 700 0.5625rem/1 'Geist Sans', Poppins, system-ui, sans-serif; + font-variant-numeric: tabular-nums; + pointer-events: none; +} diff --git a/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx b/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx index a582b0a41..94053e658 100644 --- a/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx +++ b/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx @@ -1,9 +1,10 @@ -import { useEffect, useState, type MouseEvent } from 'react' +import { useEffect, useMemo, useState, type MouseEvent } from 'react' import { ArrowRight, BedDouble, CalendarDays, CalendarRange, ChevronRight, LogIn, LogOut, Map as MapIcon, MapPin, Pencil, PencilLine, Route, Ticket, TrainFront, Undo2 } from 'lucide-react' import type { LucideIcon } from 'lucide-react' import { useContextMenu, ContextMenu } from '../../../../components/shared/ContextMenu' import MarkdownText from '../../../../components/shared/MarkdownText' import { fmtTransitDuration } from '../../../../components/Planner/transitDisplay' +import { stopNumbersOfDay } from '../../../../components/Planner/stopNumbers' import { legModeMenuItems, transitOnlyMenuItems } from '../../../../components/Planner/useLegModeActions' import { formatTime } from '../../../../utils/formatters' import { useMPlanTimeline, type MPlanTimelineController } from './useMPlanTimeline' @@ -197,6 +198,9 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen } const chrome = { editing, t, language: tl.language, timeFormat: tl.timeFormat } + // The numbers the map's pins carry, beside each stop (#2584). + const dayAssignments = planner.assignments[String(pageDayId)] + const stopNumbers = useMemo(() => stopNumbersOfDay(dayAssignments || []), [dayAssignments]) const [cardScroll, setCardScroll] = useState(null) const cardFade = useEdgeFade(cardScroll, 'y') @@ -273,6 +277,7 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen tour.place_id === row.assignment.place_id) : undefined} fullPlace={tl.fullPlaceOf(row.assignment)} linkedReservations={row.linkedReservations} diff --git a/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx b/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx index 981e2befb..bd319461f 100644 --- a/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx +++ b/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx @@ -129,8 +129,10 @@ const ROW_CODE = 'flex-none whitespace-nowrap font-geist text-[0.71875rem] text- // ── b3) Place row ──────────────────────────────────────────────────────────── -export function PlaceRow({ assignment, fullPlace, tour, linkedReservations, chrome, reorder, drag, onOpen, onEdit, onRemove, overrun }: { +export function PlaceRow({ assignment, stopNumber, fullPlace, tour, linkedReservations, chrome, reorder, drag, onOpen, onEdit, onRemove, overrun }: { assignment: Assignment + /** Its number on the map (#2584); none for a service stop. */ + stopNumber?: number fullPlace: Place | undefined tour?: TourListItem /** TIME-02: the day's next timed item this tour runs into, or null. */ @@ -182,6 +184,7 @@ export function PlaceRow({ assignment, fullPlace, tour, linkedReservations, chro className={`flex cursor-pointer items-center gap-2.5 py-1.5 ${dragClass(drag)}`} > {!chrome.editing && ( + {tour ? : } + {stopNumber != null && } + )}
diff --git a/client/src/pages/tripPlanner/useMapPlaces.ts b/client/src/pages/tripPlanner/useMapPlaces.ts index 885f0678f..636affd65 100644 --- a/client/src/pages/tripPlanner/useMapPlaces.ts +++ b/client/src/pages/tripPlanner/useMapPlaces.ts @@ -1,5 +1,5 @@ import { useEffect, useMemo, useState } from 'react' -import { isServiceStopType } from '../../components/Roadtrip/roadtripModel' +import { stopNumbersOfDay } from '../../components/Planner/stopNumbers' import { useTourMapVisibility } from '../../components/Tours/useTourMapVisibility' import { useSettingsStore } from '../../store/settingsStore' import { useTripStore, type TripStoreState } from '../../store/tripStore' @@ -106,21 +106,18 @@ export function useMapPlaces(options: MapPlacesOptions) { if (placesFilter === 'tracks' && !hasTracks) setPlacesFilter('all') }, [placesFilter, hasTracks, setPlacesFilter]) - // Build placeId → order-number map from the selected day's assignments. A service - // stop is passed over rather than counted: the map draws it without a badge and the - // rail gives it no number, so a number spent on it left the pin after a fuel stop - // wearing "3" where the rail said "2". + // Build placeId → order-number map from the selected day's assignments, through the + // count the plan's rows read too (stopNumbersOfDay), so a pin and its row agree. const dayOrderMap = useMemo(() => { if (!selectedDayId) return {} const da = assignments[String(selectedDayId)] || [] - const sorted = [...da].sort((a, b) => a.order_index - b.order_index) + const numbers = stopNumbersOfDay(da) const map = {} - let counted = 0 - sorted.forEach(a => { - if (!a.place?.id || isServiceStopType(a.place.stop_type)) return - counted += 1 + ;[...da].sort((a, b) => a.order_index - b.order_index).forEach(a => { + const n = numbers.get(a.id) + if (n === undefined || !a.place?.id) return if (!map[a.place.id]) map[a.place.id] = [] - map[a.place.id].push(counted) + map[a.place.id].push(n) }) return map }, [selectedDayId, assignments])