diff --git a/client/src/components/Journey/JourneyMap.test.tsx b/client/src/components/Journey/JourneyMap.test.tsx index 26f645133..a05695dac 100644 --- a/client/src/components/Journey/JourneyMap.test.tsx +++ b/client/src/components/Journey/JourneyMap.test.tsx @@ -1,4 +1,4 @@ -// FE-COMP-JOURNEYMAP-001 to FE-COMP-JOURNEYMAP-057 +// FE-COMP-JOURNEYMAP-001 to FE-COMP-JOURNEYMAP-058 vi.mock('../../api/websocket', () => ({ connect: vi.fn(), @@ -205,6 +205,15 @@ describe('JourneyMap', () => { expect(firstCall.html).toContain('>1<'); }); + it('FE-COMP-JOURNEYMAP-058: a stop without a number (a draft) gets an unnumbered pin', () => { + render( + + ); + const html = String(vi.mocked(L.divIcon).mock.calls[0][0]?.html); + expect(html).toContain('<\/text>/); + }); + it('FE-COMP-JOURNEYMAP-008: renders markers with mood-based entry labels', () => { const entriesWithMood = [ { id: 'e1', lat: 48.8566, lng: 2.3522, title: 'Happy Paris', mood: 'happy', entry_date: '2025-06-01' }, diff --git a/client/src/components/Journey/JourneyMap.tsx b/client/src/components/Journey/JourneyMap.tsx index 8e18c78df..1b6d72985 100644 --- a/client/src/components/Journey/JourneyMap.tsx +++ b/client/src/components/Journey/JourneyMap.tsx @@ -23,7 +23,7 @@ export interface MapMarkerItem { mood?: string | null time: string dayColor: string - dayLabel: number + dayLabel: number | null photoUrls: string[] } @@ -45,7 +45,7 @@ interface MapEntry { mood?: string | null entry_date: string dayColor?: string - dayLabel?: number + dayLabel?: number | null /** Thumbnails for the marker card, already resolved by the caller (the share view signs its own). */ photoUrls?: string[] } @@ -117,7 +117,7 @@ function buildMarkerItems(entries: MapEntry[]): MapMarkerItem[] { mood: e.mood, time: e.entry_date, dayColor: e.dayColor || '#52525B', - dayLabel: e.dayLabel ?? 1, + dayLabel: e.dayLabel === undefined ? 1 : e.dayLabel, photoUrls: e.photoUrls ?? [], }) } @@ -129,12 +129,12 @@ function buildMarkerItems(entries: MapEntry[]): MapMarkerItem[] { const MARKER_W = 28 const MARKER_H = 36 -function markerSvg(dayColor: string, dayLabel: number, highlighted: boolean, planned = false): string { +function markerSvg(dayColor: string, dayLabel: number | null, highlighted: boolean, planned = false): string { const stroke = highlighted ? '#fff' : 'rgba(255,255,255,0.5)' const shadow = highlighted ? 'filter:drop-shadow(0 0 10px rgba(0,0,0,0.4)) drop-shadow(0 2px 6px rgba(0,0,0,0.4))' : 'filter:drop-shadow(0 2px 4px rgba(0,0,0,0.25))' - const label = String(dayLabel) + const label = dayLabel === null ? '' : String(dayLabel) const scale = highlighted ? 1.2 : 1 return `
diff --git a/client/src/components/Journey/JourneyMapAuto.tsx b/client/src/components/Journey/JourneyMapAuto.tsx index ed6da85bd..494cc05ad 100644 --- a/client/src/components/Journey/JourneyMapAuto.tsx +++ b/client/src/components/Journey/JourneyMapAuto.tsx @@ -23,7 +23,8 @@ interface MapEntry { mood?: string | null entry_date: string dayColor?: string - dayLabel?: number + /** Null leaves the pin unnumbered: a draft the share link does not count. */ + dayLabel?: number | null } interface Props { diff --git a/client/src/components/Journey/JourneyMapGL.test.tsx b/client/src/components/Journey/JourneyMapGL.test.tsx index 6bb7d0068..9248a7b61 100644 --- a/client/src/components/Journey/JourneyMapGL.test.tsx +++ b/client/src/components/Journey/JourneyMapGL.test.tsx @@ -1,4 +1,4 @@ -// FE-COMP-JMAPGL-001 to FE-COMP-JMAPGL-042, FE-COMP-JMAPGL-2453 +// FE-COMP-JMAPGL-001 to FE-COMP-JMAPGL-043, FE-COMP-JMAPGL-2453 type Spy = ReturnType @@ -238,6 +238,15 @@ describe('JourneyMapGL', () => { expect(gl.markers[1].element.innerHTML).toContain('>1<') }) + it('FE-COMP-JMAPGL-043: a stop without a number (a draft) gets an unnumbered pin', () => { + withToken() + render() + + expect(gl.markers).toHaveLength(1) + expect(gl.markers[0].element.innerHTML).toContain('#ff0055') + expect(gl.markers[0].element.innerHTML).toMatch(/font-weight="700"><\/text>/) + }) + it('FE-COMP-JMAPGL-006: entries without coordinates never reach the map', () => { withToken() render( diff --git a/client/src/components/Journey/JourneyMapGL.tsx b/client/src/components/Journey/JourneyMapGL.tsx index d703ae5ad..064a2fb9b 100644 --- a/client/src/components/Journey/JourneyMapGL.tsx +++ b/client/src/components/Journey/JourneyMapGL.tsx @@ -26,7 +26,7 @@ interface MapEntry { mood?: string | null entry_date: string dayColor?: string - dayLabel?: number + dayLabel?: number | null /** Thumbnails for the marker card, already resolved by the caller (the share view signs its own). */ photoUrls?: string[] } @@ -79,7 +79,7 @@ interface Item { locationName: string time: string dayColor: string - dayLabel: number + dayLabel: number | null photoUrls: string[] } @@ -98,7 +98,7 @@ function buildItems(entries: MapEntry[]): Item[] { locationName: e.location_name || '', time: e.entry_date, dayColor: e.dayColor || '#52525B', - dayLabel: e.dayLabel ?? 1, + dayLabel: e.dayLabel === undefined ? 1 : e.dayLabel, photoUrls: e.photoUrls ?? [], }) } @@ -143,7 +143,7 @@ function addConnectionLayer(map: mapboxgl.Map, id: string, lines: [number, numbe }) } -function markerHtml(dayColor: string, dayLabel: number, highlighted: boolean, planned = false): HTMLDivElement { +function markerHtml(dayColor: string, dayLabel: number | null, highlighted: boolean, planned = false): HTMLDivElement { const fill = dayColor const textColor = '#fff' const stroke = highlighted ? '#fff' : 'rgba(255,255,255,0.5)' @@ -151,7 +151,7 @@ function markerHtml(dayColor: string, dayLabel: number, highlighted: boolean, pl ? 'drop-shadow(0 0 10px rgba(0,0,0,0.4)) drop-shadow(0 2px 6px rgba(0,0,0,0.4))' : 'drop-shadow(0 2px 4px rgba(0,0,0,0.25))' const scale = highlighted ? 1.2 : 1 - const label = String(dayLabel) + const label = dayLabel === null ? '' : String(dayLabel) // Outer wrap holds the element mapbox positions via `transform: translate(...)`. // Anything animated (scale, filter) has to live on an inner child — otherwise diff --git a/client/src/components/Journey/journeyMapStops.test.ts b/client/src/components/Journey/journeyMapStops.test.ts new file mode 100644 index 000000000..c687dbe6a --- /dev/null +++ b/client/src/components/Journey/journeyMapStops.test.ts @@ -0,0 +1,98 @@ +// FE-JRN-STOPS-001 to FE-JRN-STOPS-007 +import { describe, expect, it } from 'vitest'; +import { compareJourneyEntries, isJourneyMapEntry, journeyMapStops, type JourneyStopEntry } from './journeyMapStops'; + +function entry(over: Partial & { id: number }): JourneyStopEntry { + return { + entry_date: '2026-10-24', + sort_order: 0, + type: 'entry', + title: 'Stop', + location_lat: 35, + location_lng: 135.7, + ...over, + }; +} + +function numbers(entries: JourneyStopEntry[]): Record { + return Object.fromEntries(journeyMapStops(entries).map(({ entry: e, stop }) => [String(e.id), stop])); +} + +describe('journeyMapStops', () => { + it('FE-JRN-STOPS-001: counts through the whole journey instead of restarting each day', () => { + const entries = [ + entry({ id: 1, entry_date: '2026-10-23' }), + entry({ id: 2, entry_date: '2026-10-23', sort_order: 1 }), + entry({ id: 3, entry_date: '2026-10-23', sort_order: 2 }), + entry({ id: 4, entry_date: '2026-10-24' }), + entry({ id: 5, entry_date: '2026-10-24', sort_order: 1 }), + ]; + + expect(numbers(entries)).toEqual({ 1: 1, 2: 2, 3: 3, 4: 4, 5: 5 }); + }); + + it('FE-JRN-STOPS-002: numbers in reading order whatever order the entries arrive in', () => { + const entries = [ + entry({ id: 9, entry_date: '2026-10-24', sort_order: 1 }), + entry({ id: 7, entry_date: '2026-10-23' }), + entry({ id: 8, entry_date: '2026-10-24', sort_order: 0 }), + ]; + + expect(journeyMapStops(entries).map((s) => s.entry.id)).toEqual([7, 8, 9]); + expect(numbers(entries)).toEqual({ 7: 1, 8: 2, 9: 3 }); + }); + + it('FE-JRN-STOPS-003: a sort_order tie is broken by id, as the server orders them', () => { + const entries = [entry({ id: 12 }), entry({ id: 10 }), entry({ id: 11 })]; + + expect(journeyMapStops(entries).map((s) => s.entry.id)).toEqual([10, 11, 12]); + expect(compareJourneyEntries(entry({ id: 10 }), entry({ id: 11 }))).toBeLessThan(0); + }); + + it('FE-JRN-STOPS-004: a draft keeps its pin without a number and does not move the stops after it', () => { + const entries = [ + entry({ id: 1, entry_date: '2026-10-23' }), + entry({ id: 2, entry_date: '2026-10-23', sort_order: 1, is_draft: true }), + entry({ id: 3, entry_date: '2026-10-24' }), + ]; + + expect(numbers(entries)).toEqual({ 1: 1, 2: null, 3: 2 }); + expect(numbers(entries.filter((e) => !e.is_draft))).toEqual({ 1: 1, 3: 2 }); + }); + + it('FE-JRN-STOPS-005: skeletons, gallery placeholders and entries without coordinates stay off the map', () => { + const entries = [ + entry({ id: 1, type: 'skeleton' }), + entry({ id: 2, title: 'Gallery' }), + entry({ id: 3, title: '[Trip Photos]' }), + entry({ id: 4, location_lat: null, location_lng: null }), + entry({ id: 5, sort_order: 1 }), + ]; + + expect(numbers(entries)).toEqual({ 5: 1 }); + expect(entries.map(isJourneyMapEntry)).toEqual([false, false, false, false, true]); + }); + + it('FE-JRN-STOPS-006: the owner journal and the share link give every published stop the same number', () => { + const owner = [ + entry({ id: 21, entry_date: '2026-10-23' }), + entry({ id: 22, entry_date: '2026-10-23', sort_order: 1, is_draft: true }), + entry({ id: 23, entry_date: '2026-10-23', sort_order: 2 }), + entry({ id: 24, entry_date: '2026-10-24', type: 'skeleton' }), + entry({ id: 25, entry_date: '2026-10-24', sort_order: 1 }), + ]; + const shared = owner.filter((e) => !e.is_draft && e.type !== 'skeleton'); + + const ownerNumbers = numbers(owner); + delete ownerNumbers[22]; + expect(ownerNumbers).toEqual(numbers(shared)); + }); + + it('FE-JRN-STOPS-007: leaves the caller its list untouched', () => { + const entries = [entry({ id: 2, sort_order: 1 }), entry({ id: 1 })]; + + journeyMapStops(entries); + + expect(entries.map((e) => e.id)).toEqual([2, 1]); + }); +}); diff --git a/client/src/components/Journey/journeyMapStops.ts b/client/src/components/Journey/journeyMapStops.ts new file mode 100644 index 000000000..fa7946a54 --- /dev/null +++ b/client/src/components/Journey/journeyMapStops.ts @@ -0,0 +1,59 @@ +/** + * Which journal entries stand on a journey's map and the number each one carries. + * + * The owner's journal and the public share link both draw the same pins, and they + * used to number them by two different rules: the share link counted through the + * whole journey (#1962) while the owner's map restarted at 1 every day, so the + * same stop read 66 on one and 6 on the other (#2886). Both views now take their + * numbers from here. + */ + +export interface JourneyStopEntry { + id: number | string; + entry_date: string; + sort_order?: number | null; + title?: string | null; + type?: string | null; + is_draft?: boolean | number | null; + location_lat?: number | null; + location_lng?: number | null; +} + +export interface JourneyMapStop { + entry: E; + /** The stop's place in the whole journey, or null for a draft the share link does not show. */ + stop: number | null; +} + +/** Placeholder entries the old gallery model kept in the journal; a migration removes them, older caches may still hold them. */ +const GALLERY_PLACEHOLDER_TITLES = new Set(['Gallery', '[Trip Photos]']); + +export function isGalleryPlaceholder(entry: Pick): boolean { + return GALLERY_PLACEHOLDER_TITLES.has(entry.title ?? ''); +} + +/** A skeleton is a suggestion taken from the trip, not a place anyone wrote about. */ +export function isJourneyMapEntry(entry: JourneyStopEntry): boolean { + return !!entry.location_lat && !!entry.location_lng && entry.type !== 'skeleton' && !isGalleryPlaceholder(entry); +} + +/** The journal's reading order, the same one the server reads the entries in. */ +export function compareJourneyEntries(a: JourneyStopEntry, b: JourneyStopEntry): number { + if (a.entry_date !== b.entry_date) return a.entry_date < b.entry_date ? -1 : 1; + const bySortOrder = (a.sort_order ?? 0) - (b.sort_order ?? 0); + if (bySortOrder !== 0) return bySortOrder; + return Number(a.id) - Number(b.id); +} + +/** + * The located entries in reading order, each with its stop number. A draft keeps + * its pin for the people writing the journal but takes no number, so every stop + * after it reads the same as on the share link, which leaves drafts out. + */ +export function journeyMapStops(entries: readonly E[]): JourneyMapStop[] { + let stop = 0; + return entries + .filter(isJourneyMapEntry) + .sort(compareJourneyEntries) + .map((entry) => ({ entry, stop: entry.is_draft ? null : ++stop })); +} diff --git a/client/src/pages/journeyDetail/useJourneyDetail.test.tsx b/client/src/pages/journeyDetail/useJourneyDetail.test.tsx index c3533d3e4..b4e8a2ef0 100644 --- a/client/src/pages/journeyDetail/useJourneyDetail.test.tsx +++ b/client/src/pages/journeyDetail/useJourneyDetail.test.tsx @@ -1,4 +1,4 @@ -// FE-JRN-DETHOOK-001 to FE-JRN-DETHOOK-039 +// FE-JRN-DETHOOK-001 to FE-JRN-DETHOOK-041 import { describe, it, expect, beforeEach, afterEach, vi, type Mock } from 'vitest'; import { useLocation, useSearchParams } from 'react-router'; import { delay, http, HttpResponse } from 'msw'; @@ -490,6 +490,35 @@ describe('useJourneyDetail', () => { expect(latest.sidebarMapItems[0].dayColor).toBe(latest.sidebarMapItems[1].dayColor); }); + it('FE-JRN-DETHOOK-040: the map counts its stops through the whole journey, as the share link does (#2886)', async () => { + serveJourney(buildDetail({ + entries: [ + buildEntry({ id: 1 }), + buildEntry({ id: 2, sort_order: 1 }), + buildEntry({ id: 3, sort_order: 2 }), + buildEntry({ id: 4, entry_date: '2026-05-02' }), + buildEntry({ id: 5, entry_date: '2026-05-02', sort_order: 1 }), + ], + })); + setup(); + await waitFor(() => expect(latest.sidebarMapItems).toHaveLength(5)); + expect(latest.sidebarMapItems.map(m => [m.id, m.dayLabel])).toEqual([['1', 1], ['2', 2], ['3', 3], ['4', 4], ['5', 5]]); + expect(latest.sidebarMapItems[3].dayColor).not.toBe(latest.sidebarMapItems[2].dayColor); + }); + + it('FE-JRN-DETHOOK-041: a draft keeps its pin without a number, so the published stops read as on the share link', async () => { + serveJourney(buildDetail({ + entries: [ + buildEntry({ id: 1 }), + buildEntry({ id: 2, sort_order: 1, is_draft: true }), + buildEntry({ id: 3, entry_date: '2026-05-02' }), + ], + })); + setup(); + await waitFor(() => expect(latest.sidebarMapItems).toHaveLength(3)); + expect(latest.sidebarMapItems.map(m => [m.id, m.dayLabel])).toEqual([['1', 1], ['2', null], ['3', 2]]); + }); + it('FE-JRN-DETHOOK-2453: geotagged gallery photos become the map layer, and a tap opens them', async () => { serveJourney(buildDetail({ gallery: [ diff --git a/client/src/pages/journeyDetail/useJourneyDetail.ts b/client/src/pages/journeyDetail/useJourneyDetail.ts index 56ed72c6f..3476cf0eb 100644 --- a/client/src/pages/journeyDetail/useJourneyDetail.ts +++ b/client/src/pages/journeyDetail/useJourneyDetail.ts @@ -5,6 +5,7 @@ import { useTranslation } from '../../i18n' import { addListener, removeListener } from '../../api/websocket' import { journeyApi } from '../../api/client' import { DAY_COLORS } from '../../components/Journey/dayColors' +import { isGalleryPlaceholder, isJourneyMapEntry, journeyMapStops } from '../../components/Journey/journeyMapStops' import type { JourneyMapAutoHandle as JourneyMapHandle } from '../../components/Journey/JourneyMapAuto' import { useToast } from '../../components/shared/Toast' import { useIsMobile } from '../../hooks/useIsMobile' @@ -421,31 +422,22 @@ export function useJourneyDetail({ journeyId, embedded = false }: JourneyDetailO return lockBodyScroll() }, [isMobile, embedded]) - // Map only shows real journal entries — skeletons are trip-derived - // suggestions, not something the user actually journaled at that spot. const mapEntries = useMemo( - () => (current?.entries || []).filter(e => - e.location_lat && e.location_lng && - e.title !== 'Gallery' && - e.title !== '[Trip Photos]' && - e.type !== 'skeleton' - ), + () => (current?.entries || []).filter(isJourneyMapEntry), [current?.entries] ) + // Numbered by the rule the share link uses, so a stop reads the same here as + // for the people the journey is shared with (#2886). const sidebarMapItems = useMemo(() => { const allDates = [...new Set( (current?.entries || []) - .filter(e => e.title !== 'Gallery' && e.title !== '[Trip Photos]') + .filter(e => !isGalleryPlaceholder(e)) .map(e => e.entry_date) .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)) )] - const sorted = [...mapEntries].sort((a, b) => a.entry_date.localeCompare(b.entry_date)) - const dayCounters = new Map() - return sorted.map(e => { + return journeyMapStops(mapEntries).map(({ entry: e, stop }) => { const dayIdx = allDates.indexOf(e.entry_date) - const dayLabel = (dayCounters.get(e.entry_date) ?? 0) + 1 - dayCounters.set(e.entry_date, dayLabel) return { id: String(e.id), lat: e.location_lat!, @@ -456,7 +448,7 @@ export function useJourneyDetail({ journeyId, embedded = false }: JourneyDetailO created_at: e.entry_date, entry_date: e.entry_date, dayColor: DAY_COLORS[dayIdx % DAY_COLORS.length], - dayLabel, + dayLabel: stop, // A glimpse of the entry's own pictures on its marker card. Three is what // the card has room for; the rest are one tap away in the entry itself. photoUrls: (e.photos ?? []).slice(0, 3).map(p => `/api/photos/${p.photo_id}/thumbnail`), diff --git a/client/src/pages/journeyPublic/journeyPublicModel.ts b/client/src/pages/journeyPublic/journeyPublicModel.ts index 738becff5..f14a3a110 100644 --- a/client/src/pages/journeyPublic/journeyPublicModel.ts +++ b/client/src/pages/journeyPublic/journeyPublicModel.ts @@ -6,6 +6,8 @@ export interface PublicEntry { id: number + type?: string | null + sort_order?: number | null title?: string | null story?: string | null entry_date: string diff --git a/client/src/pages/journeyPublic/useJourneyPublic.test.tsx b/client/src/pages/journeyPublic/useJourneyPublic.test.tsx new file mode 100644 index 000000000..a340c86da --- /dev/null +++ b/client/src/pages/journeyPublic/useJourneyPublic.test.tsx @@ -0,0 +1,101 @@ +// FE-JRN-PUBHOOK-001 to FE-JRN-PUBHOOK-002 +import { http, HttpResponse } from 'msw'; +import { describe, expect, it, vi } from 'vitest'; +import { server } from '../../../tests/helpers/msw/server'; +import { render, waitFor } from '../../../tests/helpers/render'; +import type { PublicEntry } from './journeyPublicModel'; +import { useJourneyPublic } from './useJourneyPublic'; + +vi.mock('react-router', async () => { + const actual = await vi.importActual('react-router'); + return { ...actual, useParams: () => ({ token: 'tok-1' }) }; +}); + +vi.mock('../../hooks/useIsMobile', () => ({ useIsMobile: () => false })); + +function buildEntry(over: Partial & { id: number }): PublicEntry { + return { + title: 'Stop', + story: null, + entry_date: '2026-10-23', + entry_time: null, + type: 'entry', + sort_order: 0, + location_name: 'Kyoto', + location_lat: 35, + location_lng: 135.7, + mood: null, + weather: null, + pros_cons: null, + photos: [], + ...over, + }; +} + +function serveShare(entries: PublicEntry[]): void { + server.use( + http.get('/api/public/journey/tok-1', () => + HttpResponse.json({ + journey: { title: 'Japan' }, + entries, + gallery: [], + permissions: { share_timeline: true, share_gallery: true, share_map: false }, + stats: {}, + }) + ) + ); +} + +let latest: ReturnType; + +function Harness() { + latest = useJourneyPublic(); + return null; +} + +describe('useJourneyPublic', () => { + it('FE-JRN-PUBHOOK-001: the map and the timeline count the stops through the whole journey', async () => { + serveShare([ + buildEntry({ id: 1 }), + buildEntry({ id: 2, sort_order: 1 }), + buildEntry({ id: 3, sort_order: 2 }), + buildEntry({ id: 4, entry_date: '2026-10-24' }), + buildEntry({ id: 5, entry_date: '2026-10-24', sort_order: 1 }), + ]); + render(); + + await waitFor(() => expect(latest.sidebarMapItems).toHaveLength(5)); + expect(latest.sidebarMapItems.map((m) => [m.id, m.dayLabel])).toEqual([ + ['1', 1], + ['2', 2], + ['3', 3], + ['4', 4], + ['5', 5], + ]); + expect([...latest.stopNumberById]).toEqual([ + ['1', 1], + ['2', 2], + ['3', 3], + ['4', 4], + ['5', 5], + ]); + }); + + it('FE-JRN-PUBHOOK-002: entries sharing a sort_order are numbered by id, as the owner journal numbers them', async () => { + serveShare([ + buildEntry({ id: 8 }), + buildEntry({ id: 6 }), + buildEntry({ id: 7, location_lat: null, location_lng: null }), + buildEntry({ id: 9, entry_date: '2026-10-24' }), + ]); + render(); + + await waitFor(() => expect(latest.sidebarMapItems).toHaveLength(3)); + expect(latest.sidebarMapItems.map((m) => [m.id, m.dayLabel])).toEqual([ + ['6', 1], + ['8', 2], + ['9', 3], + ]); + expect(latest.stopNumberById.has('7')).toBe(false); + }); +}); diff --git a/client/src/pages/journeyPublic/useJourneyPublic.ts b/client/src/pages/journeyPublic/useJourneyPublic.ts index f889e88bf..94ac85249 100644 --- a/client/src/pages/journeyPublic/useJourneyPublic.ts +++ b/client/src/pages/journeyPublic/useJourneyPublic.ts @@ -5,6 +5,7 @@ import { useSettingsStore } from '../../store/settingsStore' import type { JourneyMapHandle } from '../../components/Journey/JourneyMap' import { useIsMobile } from '../../hooks/useIsMobile' import { DAY_COLORS } from '../../components/Journey/dayColors' +import { journeyMapStops } from '../../components/Journey/journeyMapStops' import { posterlessVideo } from '../journeyDetail/JourneyDetailPage.helpers' import { groupByDate, type PublicEntry, type PublicGalleryPhoto } from './journeyPublicModel' import { useJourneyMapLayers } from '../../components/Journey/useJourneyMapLayers' @@ -58,10 +59,6 @@ export function useJourneyPublic() { // Chronological throughout: this is what the day colours and the stop numbers are // derived from, so flipping the reading order must not renumber the trip. const sortedDates = useMemo(() => [...groupedEntries.keys()].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)), [groupedEntries]) - const mapEntries = useMemo( - () => timelineEntries.filter(e => e.location_lat && e.location_lng), - [timelineEntries], - ) const allPhotos = gallery // Map entries with day color/label for colored markers. @@ -73,10 +70,8 @@ export function useJourneyPublic() { // 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(() => { - let stop = 0 - return mapEntries.map(e => { + return journeyMapStops(timelineEntries).map(({ entry: e, stop }) => { const dayIdx = sortedDates.indexOf(e.entry_date) - const dayLabel = ++stop return { id: String(e.id), lat: e.location_lat!, @@ -86,7 +81,7 @@ export function useJourneyPublic() { created_at: e.entry_date, entry_date: e.entry_date, dayColor: DAY_COLORS[dayIdx % DAY_COLORS.length], - dayLabel, + dayLabel: stop, // Through the share token, like every other picture on this page: the // reader has no session, so `/api/photos/:id` would answer 401. The // poster rather than the file, as the owner's own map card does, since @@ -98,13 +93,15 @@ export function useJourneyPublic() { .map(p => `/api/public/journey/${token}/photos/${p.photo_id}/thumbnail`), } }) - }, [mapEntries, sortedDates, token]) + }, [timelineEntries, sortedDates, token]) // 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() - sidebarMapItems.forEach(i => m.set(i.id, i.dayLabel)) + sidebarMapItems.forEach(i => { + if (i.dayLabel !== null) m.set(i.id, i.dayLabel) + }) return m }, [sidebarMapItems]) diff --git a/server/src/db/repositories/JourneyEntries.repository.ts b/server/src/db/repositories/JourneyEntries.repository.ts index 02da045cd..a21744cc2 100644 --- a/server/src/db/repositories/JourneyEntries.repository.ts +++ b/server/src/db/repositories/JourneyEntries.repository.ts @@ -138,11 +138,12 @@ export class JourneyEntriesRepository extends TrekRepository { * JS13 (Plan 4 Task 8b relocation) — the public `getPublicJourney` route's * entry list: `SELECT je.* FROM journey_entries je WHERE je.journey_id=? * AND je.type != 'skeleton' AND je.dismissed=0 AND je.is_draft=0 (#696, a draft - * stays off the share link) ORDER BY je.entry_date, - * je.sort_order`. A narrower filter than {@link listForJourney}/JG14 (adds - * the `type != 'skeleton'` exclusion — skeletons never appear publicly — - * and has no `id` ORDER BY tiebreak), so this is a distinct method, not a - * call to {@link listForJourney}. Previously lived as + * stays off the share link) ORDER BY je.entry_date, je.sort_order, je.id`. + * A narrower filter than {@link listForJourney}/JG14 (adds the + * `type != 'skeleton'` exclusion — skeletons never appear publicly), so this + * is a distinct method, not a call to {@link listForJourney}. The order is + * JG14's, `id` tiebreak included: the share link numbers its map stops in this + * order and has to number them as the owner's journal does (#2886). Previously lived as * `JourneyShareTokens.repository.ts`'s own fallback stub from 3g Task 3 * (this repository was still mid-flight when that task landed) — * relocated here now that it is stable. @@ -151,7 +152,7 @@ export class JourneyEntriesRepository extends TrekRepository { return await this.qb('je') .select(['je.*']) .where({ journey: journeyId, type: { $ne: 'skeleton' }, dismissed: 0, is_draft: 0 }) - .orderBy({ entry_date: 'asc', sort_order: 'asc' }) + .orderBy({ entry_date: 'asc', sort_order: 'asc', id: 'asc' }) .execute('all', false); } diff --git a/server/tests/unit/nest/journey-share.service.test.ts b/server/tests/unit/nest/journey-share.service.test.ts index 4c1380c80..7631d6a62 100644 --- a/server/tests/unit/nest/journey-share.service.test.ts +++ b/server/tests/unit/nest/journey-share.service.test.ts @@ -1016,7 +1016,7 @@ describe('parity — JourneyShareTokensRepository reads match the legacy stateme ` SELECT je.* FROM journey_entries je WHERE je.journey_id = ? AND je.type != 'skeleton' AND je.dismissed = 0 - ORDER BY je.entry_date, je.sort_order + ORDER BY je.entry_date, je.sort_order, je.id `, ) .all(journey.id); @@ -1024,6 +1024,20 @@ describe('parity — JourneyShareTokensRepository reads match the legacy stateme expect(await journeyEntriesRepo.listPublicEntries(journey.id)).toEqual(legacy); }); + it('JOURNEY-SHARE-P04b: listPublicEntries breaks a sort_order tie by id, as the owner journal does (#2886)', async () => { + const { user } = createUser(testDb); + const journey = createJourney(testDb, user.id); + const first = createJourneyEntry(testDb, journey.id, user.id, { type: 'entry', entry_date: '2026-01-01' }); + const second = createJourneyEntry(testDb, journey.id, user.id, { type: 'entry', entry_date: '2026-01-01' }); + const third = createJourneyEntry(testDb, journey.id, user.id, { type: 'entry', entry_date: '2026-01-01' }); + await updateRows(t, JourneyEntries, { id: third.id }, { sort_order: -1 }); + + const ids = (await journeyEntriesRepo.listPublicEntries(journey.id)).map((e) => e.id); + + expect(ids).toEqual([third.id, first.id, second.id]); + expect(ids).toEqual((await journeyEntriesRepo.listForJourney(journey.id)).map((e) => e.id)); + }); + it('JOURNEY-SHARE-P05: JourneyEntryPhotosRepository.listForPublicJourney (JS14) matches the legacy JP_SELECT-shaped statement', async () => { const { user } = createUser(testDb); const journey = createJourney(testDb, user.id);