mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(journey): give the public map one numbering instead of two
The marker showed the stop's position within its day; the day heading showed the day number. Same colour, different meaning, and on mobile the heading is not rendered at all, so the number had no key — which is exactly what the report described: the same digits over and over in different colours (#1962). Both now count stops across the whole journey, so every number appears once, and the timeline carries the same number next to each geocoded entry. The day colour still groups the day. The badge sits outside the photo-count gate on purpose: an entry with a single photo puts its title and location in the image overlay, but the stop number has to be readable either way.
This commit is contained in:
@@ -536,4 +536,26 @@ describe('JourneyPublicPage', () => {
|
||||
expect(images.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// #1962 — the marker number used to be the stop's position within its day while
|
||||
// the day heading showed the day number, so the same digit appeared repeatedly in
|
||||
// different colours with no key. Both now count stops across the whole journey.
|
||||
it('FE-PAGE-PUBLICJOURNEY-021: numbers each stop once, and the timeline carries the same number', async () => {
|
||||
setupSuccess();
|
||||
render(<JourneyPublicPage />);
|
||||
|
||||
await waitFor(() => expect(screen.getByText('Shibuya Crossing')).toBeInTheDocument());
|
||||
|
||||
// Two geocoded entries on two different days: stops 1 and 2, not 1 and 1.
|
||||
const shibuya = document.querySelector('[data-entry-id="10"]') as HTMLElement;
|
||||
const sensoji = document.querySelector('[data-entry-id="11"]') as HTMLElement;
|
||||
expect(shibuya).toBeTruthy();
|
||||
expect(sensoji).toBeTruthy();
|
||||
|
||||
const badge = (el: HTMLElement) =>
|
||||
Array.from(el.querySelectorAll('span')).find(s => /^\d+$/.test(s.textContent || ''))?.textContent;
|
||||
|
||||
expect(badge(shibuya)).toBe('1');
|
||||
expect(badge(sensoji)).toBe('2');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -112,6 +112,7 @@ export default function JourneyPublicPage() {
|
||||
sortedDates,
|
||||
sidebarMapItems,
|
||||
allPhotos,
|
||||
stopNumberById,
|
||||
desktopTwoColumn,
|
||||
} = useJourneyPublic();
|
||||
|
||||
@@ -304,6 +305,22 @@ export default function JourneyPublicPage() {
|
||||
</h3>
|
||||
)}
|
||||
|
||||
{/* The number the map marker carries, so the timeline is the key
|
||||
to the map rather than a second, unrelated numbering (#1962).
|
||||
Outside the photo-count gate below: a single-photo entry puts
|
||||
its title and location in the image overlay, but the stop
|
||||
number has to be readable either way. */}
|
||||
{stopNumberById.has(String(entry.id)) && (
|
||||
<div className="mb-2">
|
||||
<span
|
||||
className="inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-full px-1.5 text-[10px] font-bold text-white"
|
||||
style={{ background: dayColor }}
|
||||
>
|
||||
{stopNumberById.get(String(entry.id))}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Location + time badges */}
|
||||
{(entry.location_name || entry.entry_time) && photos.length !== 1 && (
|
||||
<div className="mb-2 flex flex-wrap items-center gap-2">
|
||||
|
||||
@@ -82,6 +82,7 @@ function buildHook(over: Record<string, unknown> = {}): Record<string, unknown>
|
||||
groupedEntries: grouped,
|
||||
sortedDates: [...grouped.keys()].sort(),
|
||||
sidebarMapItems: [],
|
||||
stopNumberById: new Map<string, number>(),
|
||||
allPhotos: [] as PublicGalleryPhoto[],
|
||||
desktopTwoColumn: true,
|
||||
...over,
|
||||
|
||||
@@ -63,12 +63,16 @@ export function useJourneyPublic() {
|
||||
// Map entries with day color/label for colored markers.
|
||||
// dayIdx is derived from sortedDates (ALL timeline dates) so marker colors
|
||||
// stay in sync with the timeline day headers even when some days have no locations.
|
||||
// The marker number used to be the stop's position *within* its day, while the
|
||||
// timeline heading showed the day number — two different numbers in the same
|
||||
// colour, and on mobile the heading is not rendered at all, so the key was
|
||||
// missing entirely (#1962). It is now the stop's place in the whole journey, so
|
||||
// every number appears exactly once and the colour still groups the day.
|
||||
const sidebarMapItems = useMemo(() => {
|
||||
const counters = new Map<string, number>()
|
||||
let stop = 0
|
||||
return mapEntries.map(e => {
|
||||
const dayIdx = sortedDates.indexOf(e.entry_date)
|
||||
const dayLabel = (counters.get(e.entry_date) ?? 0) + 1
|
||||
counters.set(e.entry_date, dayLabel)
|
||||
const dayLabel = ++stop
|
||||
return {
|
||||
id: String(e.id),
|
||||
lat: e.location_lat!,
|
||||
@@ -83,6 +87,14 @@ export function useJourneyPublic() {
|
||||
})
|
||||
}, [mapEntries, sortedDates])
|
||||
|
||||
// The same number the marker carries, so the timeline is the key to the map
|
||||
// rather than a second, unrelated numbering.
|
||||
const stopNumberById = useMemo(() => {
|
||||
const m = new Map<string, number>()
|
||||
sidebarMapItems.forEach(i => m.set(i.id, i.dayLabel))
|
||||
return m
|
||||
}, [sidebarMapItems])
|
||||
|
||||
// Two-column desktop layout: timeline feed left + sticky map right
|
||||
const desktopTwoColumn = !isMobile && perms.share_timeline && perms.share_map
|
||||
|
||||
@@ -102,7 +114,7 @@ export function useJourneyPublic() {
|
||||
view, setView, lightbox, setLightbox, showLangPicker, setShowLangPicker,
|
||||
mapRef, activeEntryId, setActiveEntryId, viewingEntry, setViewingEntry, handleMarkerClick,
|
||||
perms, journey, stats,
|
||||
timelineEntries, groupedEntries, sortedDates, sidebarMapItems, allPhotos,
|
||||
timelineEntries, groupedEntries, sortedDates, sidebarMapItems, allPhotos, stopNumberById,
|
||||
desktopTwoColumn,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user