feat(mobile): number the stops of a day in the plan as their pins are

The map numbers a day's stops on their pins, the phone's plan did not, so
matching a pin to its row meant reading names. Each stop now carries its
number at the foot of its picture, in the pin's dark round. The count moved
into stopNumbersOfDay, which the map reads too, so a row and its pin always
agree, service stops passed over on both.

Addresses discussion #2584.
This commit is contained in:
Maurice
2026-11-27 23:17:49 +01:00
parent fd6d1969f5
commit 20d10d765d
6 changed files with 89 additions and 13 deletions
@@ -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<NonNullable<Assignment['place']>> | 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);
});
});
@@ -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<number, number> {
const numbers = new Map<number, number>();
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;
}
+20
View File
@@ -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;
}
@@ -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<HTMLDivElement | null>(null)
const cardFade = useEdgeFade(cardScroll, 'y')
@@ -273,6 +277,7 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen
<Fragment key={row.key}>
<PlaceRow
assignment={row.assignment}
stopNumber={stopNumbers.get(row.assignment.id)}
tour={planner.toursEnabled ? planner.tours.find(tour => tour.place_id === row.assignment.place_id) : undefined}
fullPlace={tl.fullPlaceOf(row.assignment)}
linkedReservations={row.linkedReservations}
@@ -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 && (
<span className="relative flex-none">
<AvatarRing className="shadow-[0_3px_8px_-3px_rgba(0,0,0,.4)]">
{tour ? <TourDayRowIcon type={tour.tour_type} /> : <PlaceAvatar
place={fullPlace ?? {
@@ -197,6 +200,8 @@ export function PlaceRow({ assignment, fullPlace, tour, linkedReservations, chro
category={place?.category ? { color: place.category.color ?? undefined, icon: place.category.icon ?? undefined } : null}
/>}
</AvatarRing>
{stopNumber != null && <span className="m-stop-num" aria-hidden="true">{stopNumber}</span>}
</span>
)}
<div className="min-w-0 flex-1">
<div className="flex items-center gap-1.5">
+8 -11
View File
@@ -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])