fix(journey): number map stops the same way in the journal and on the share link

The share link has counted its map stops through the whole journey since
#1962, while the owner's journal still restarted the count every day, so
the same stop read 66 on the link and 6 in the journal.

Both views now take their stops from one helper, journeyMapStops: located,
non-skeleton entries in the server's reading order (date, sort_order, id),
numbered across the journey. A draft keeps its pin in the journal but gets
no number, so the published stops after it carry exactly the numbers the
share link shows. The public entry query gains the id tiebreak the owner
query already had, so entries sharing a sort_order come back in the same
order on both sides.

Closes #2886
This commit is contained in:
Maurice
2026-10-29 16:59:25 +01:00
parent 66bff5c342
commit fe24dd03c5
14 changed files with 358 additions and 46 deletions
@@ -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(
<JourneyMap checkins={[]} entries={[{ ...entriesWithCoords[0], dayLabel: null }]} />
);
const html = String(vi.mocked(L.divIcon).mock.calls[0][0]?.html);
expect(html).toContain('<svg');
expect(html).toMatch(/font-weight="700"><\/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' },
+5 -5
View File
@@ -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 `<div style="transform:scale(${scale});transition:transform 0.2s ease;${shadow};transform-origin:bottom center">
@@ -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 {
@@ -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<typeof vi.fn>
@@ -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(<JourneyMapGL checkins={[]} entries={[{ ...entries[0], dayLabel: null }]} />)
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(
@@ -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
@@ -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<JourneyStopEntry> & { 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<string, number | null> {
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]);
});
});
@@ -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<E> {
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<JourneyStopEntry, 'title'>): 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<E extends JourneyStopEntry>(entries: readonly E[]): JourneyMapStop<E>[] {
let stop = 0;
return entries
.filter(isJourneyMapEntry)
.sort(compareJourneyEntries)
.map((entry) => ({ entry, stop: entry.is_draft ? null : ++stop }));
}
@@ -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: [
@@ -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<string, number>()
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`),
@@ -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
@@ -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<typeof import('react-router')>('react-router');
return { ...actual, useParams: () => ({ token: 'tok-1' }) };
});
vi.mock('../../hooks/useIsMobile', () => ({ useIsMobile: () => false }));
function buildEntry(over: Partial<PublicEntry> & { 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<typeof useJourneyPublic>;
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(<Harness />);
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(<Harness />);
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);
});
});
@@ -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<string, number>()
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])
@@ -138,11 +138,12 @@ export class JourneyEntriesRepository extends TrekRepository<JourneyEntries> {
* 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<JourneyEntries> {
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<JourneyEntry[]>('all', false);
}
@@ -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);