feat(journey): make the linked trips' GPX tracks a switch, off by default

#1260 drew the GPX tracks of every trip behind a journey onto its map, with
nothing to switch off — the reasoning being that a route imported into a
linked trip is part of the journey's story. For a trip carrying a season of
recorded drives it is instead a map nobody asked for, drawn from places that
never became an entry.

So it becomes a journey-level setting, owner-only like the other Journey
Settings, and it starts off: a journal should show what its author put in it,
and #1260's set is everything the linked trips happen to contain. The switch
gates the request, not just the rendering — the endpoint ships full unthinned
geometry, which is megabytes fetched on every journey open for a map nobody
wanted.

`journeyTracks()` itself is deliberately untouched, so TREK Studio keeps the
set its saved books were laid out with.

Also fixes what the reporter's screenshot actually shows: JourneyMap fed track
coordinates into `fitBounds`, so one drive across a country zoomed the journey
map out until the entries were specks. Tracks now only frame the map when
there is nothing else to frame, which is what JourneyMapGL already did — the
same journey used to open at two different zooms depending on the renderer.

Closes #2194

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S5VwmiBQ9sPCJwfmpv64r3
This commit is contained in:
Claude
2026-09-02 12:01:14 +00:00
committed by Maurice
parent 5e5fe288d8
commit b7f9c1e8ae
31 changed files with 211 additions and 13 deletions
@@ -77,6 +77,21 @@ export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite,
}
}
// Saved on the spot rather than on Save, like the archive switch above it:
// it is a view setting, and the point of it is seeing the map change (#2194).
const [savingTracks, setSavingTracks] = useState(false)
const handleTracksToggle = async () => {
setSavingTracks(true)
try {
await updateJourney(journey.id, { show_trip_tracks: !journey.show_trip_tracks })
onSaved()
} catch {
toast.error(t('journey.settings.saveFailed'))
} finally {
setSavingTracks(false)
}
}
const handleDelete = async () => {
try {
await deleteJourney(journey.id)
@@ -141,6 +156,30 @@ export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite,
/>
</div>
{/* Trip GPX tracks on the journey map (#2194) */}
<div>
<label className="text-[10px] font-semibold tracking-[0.12em] uppercase text-zinc-500 block mb-1.5">{t('journey.settings.tracks')}</label>
<button
type="button"
role="switch"
aria-checked={!!journey.show_trip_tracks}
disabled={savingTracks}
onClick={handleTracksToggle}
className="w-full flex items-center gap-3 px-3.5 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-xl bg-white dark:bg-zinc-800 text-left disabled:opacity-60"
>
<span className="flex-1 min-w-0">
<span className="block text-[14px] text-zinc-900 dark:text-white">{t('journey.settings.showTripTracks')}</span>
<span className="block text-[11px] text-zinc-500">{t('journey.settings.showTripTracksHint')}</span>
</span>
<span
aria-hidden="true"
className={`w-9 h-5 rounded-full flex-shrink-0 p-0.5 transition-colors ${journey.show_trip_tracks ? 'bg-emerald-500' : 'bg-zinc-300 dark:bg-zinc-600'}`}
>
<span className={`block w-4 h-4 rounded-full bg-white transition-transform ${journey.show_trip_tracks ? 'translate-x-4' : ''}`} />
</span>
</button>
</div>
</div>
{/* Right column */}
+18 -3
View File
@@ -268,6 +268,18 @@ function JourneyMap(
itemsRef.current = items
const allCoords: L.LatLngTuple[] = []
/**
* Track geometry is kept OUT of the fit set (#2194) and used only when there
* is nothing else to frame.
*
* A journey's opening viewport should show the journey — its entries and the
* trail between them. Letting a recorded GPX into the bounds meant one drive
* across a country zoomed the map out until the entries were specks, which
* is what the reporter's screenshot shows. JourneyMapGL already fits on
* entries + trail alone (JourneyMapGL.tsx), so this also ends an asymmetry
* where the same journey framed differently per renderer.
*/
const trackCoords: L.LatLngTuple[] = []
if (stableTrail.length > 1) {
const coords = stableTrail.map(p => [p.lat, p.lng] as L.LatLngTuple)
@@ -293,7 +305,7 @@ function JourneyMap(
// becomes innerHTML, and a track name is a place name off a shared trip.
if (track.name) line.bindTooltip(escapeHtml(track.name), { sticky: true, direction: 'top', className: 'map-tooltip' })
line.addTo(map)
coords.forEach(c => allCoords.push(c))
coords.forEach(c => trackCoords.push(c))
}
// route polyline — only in non-fullscreen (sidebar map) mode
@@ -341,9 +353,12 @@ function JourneyMap(
if (!mapRef.current) return
try {
map.invalidateSize()
if (allCoords.length > 0) {
// Tracks only get a say when the journey has nothing located of its own —
// a world view would be worse than framing the one thing on the map.
const fitCoords = allCoords.length > 0 ? allCoords : trackCoords
if (fitCoords.length > 0) {
const pb = paddingBottom || 50
map.fitBounds(L.latLngBounds(allCoords), { paddingTopLeft: [50, 50], paddingBottomRight: [50, pb], maxZoom: 16 })
map.fitBounds(L.latLngBounds(fitCoords), { paddingTopLeft: [50, 50], paddingBottomRight: [50, pb], maxZoom: 16 })
} else {
map.setView([30, 0], 2)
}
@@ -13,6 +13,9 @@ import { lockBodyScroll } from '../../utils/bodyScrollLock'
import type { JourneyEntry } from '../../store/journeyStore'
import { createDraftJourneyEntry } from './JourneyDetailPage.helpers'
/** Stable identity for "this journey draws no trip tracks" (#2194). */
const NO_TRACKS: JourneyTrack[] = []
/**
* Journey detail page logic — owns the journey load + WebSocket live sync, the
* timeline/gallery view state, the entry editor/viewer/delete/lightbox dialogs,
@@ -71,18 +74,31 @@ export function useJourneyDetail() {
if (id) loadJourney(Number(id)).catch(() => {})
}, [id])
// GPX tracks of the trips behind this journey (#1260). Loaded separately from the
// journey itself: a journey without tracks is the common case, and a failed lookup
// should cost the map its lines, not the whole page.
const [tracks, setTracks] = useState<JourneyTrack[]>([])
// GPX tracks of the trips behind this journey (#1260), drawn only when the
// journey asks for them (#2194). Loaded separately from the journey itself: a
// journey without tracks is the common case, and a failed lookup should cost
// the map its lines, not the whole page.
//
// The switch gates the REQUEST, not just the rendering: the endpoint ships
// full unthinned geometry, which for a trip carrying a season of recorded
// drives is megabytes fetched on every journey open for a map nobody asked
// for. It stays untouched on the server so TREK Studio, which freezes the
// same endpoint's output into a saved book, keeps the set it laid out with.
const [tracks, setTracks] = useState<JourneyTrack[]>(NO_TRACKS)
const showTripTracks = !!current?.show_trip_tracks
useEffect(() => {
if (!id) return
if (!id || !showTripTracks) {
// A stable empty array: a fresh literal here would be a new reference on
// every toggle and re-render the map for nothing.
setTracks(NO_TRACKS)
return
}
let cancelled = false
journeyApi.listTracks(Number(id))
.then(res => { if (!cancelled) setTracks(res.tracks ?? []) })
.catch(() => { if (!cancelled) setTracks([]) })
.then(res => { if (!cancelled) setTracks(res.tracks ?? NO_TRACKS) })
.catch(() => { if (!cancelled) setTracks(NO_TRACKS) })
return () => { cancelled = true }
}, [id])
}, [id, showTripTracks])
useEffect(() => {
if (current?.hide_skeletons !== undefined) setHideSkeletons(current.hide_skeletons)
+6
View File
@@ -11,6 +11,12 @@ export interface Journey {
cover_gradient?: string | null
cover_image?: string | null
status: 'draft' | 'active' | 'completed' | 'archived'
/**
* Draw the GPX tracks of the journey's linked trips on its map (#2194).
* Off unless the owner asks for it — see the migration for why the default
* flipped. Optional so a cached pre-#2194 journey still parses.
*/
show_trip_tracks?: boolean
created_at: number
updated_at: number
}