From bd2bdebc3318cb88aa130cab1f1481635d7eb059 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 18 Apr 2026 01:43:55 +0200 Subject: [PATCH] feat(map): auto-fit the planner map to the trip's places on load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the annoyance from discussion #510 — the planner opened every trip centered on the global default, even when the trip's places were on the other side of the world. We already have a BoundsController that fits the map on the current places when fitKey changes, so nudging fitKey once per trip (after the places have loaded) gives each trip its own starting view without any new settings or UI. If a trip has no places with coordinates yet, the global default still applies. --- client/src/pages/TripPlannerPage.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/src/pages/TripPlannerPage.tsx b/client/src/pages/TripPlannerPage.tsx index b8b5dc50..abecfdc5 100644 --- a/client/src/pages/TripPlannerPage.tsx +++ b/client/src/pages/TripPlannerPage.tsx @@ -233,9 +233,19 @@ export default function TripPlannerPage(): React.ReactElement | null { const [showReservationModal, setShowReservationModal] = useState(false) const [editingReservation, setEditingReservation] = useState(null) const [fitKey, setFitKey] = useState(0) + const initialFitTripId = useRef(null) const [mobileSidebarOpen, setMobileSidebarOpen] = useState<'left' | 'right' | null>(null) const [deletePlaceId, setDeletePlaceId] = useState(null) + useEffect(() => { + if (!trip) return + if (initialFitTripId.current === trip.id) return + const hasGeoPlaces = places.some(p => p.lat != null && p.lng != null) + if (!hasGeoPlaces) return + initialFitTripId.current = trip.id + setFitKey(k => k + 1) + }, [trip, places]) + const connectionsStorageKey = tripId ? `trek:visible-connections:${tripId}` : null const [visibleConnections, setVisibleConnections] = useState(() => { if (typeof window === 'undefined' || !connectionsStorageKey) return []