Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat(map): auto-fit the planner map to the trip's places on load

Mauricebd2bdebc3318
diff --git a/client/src/pages/TripPlannerPage.tsx b/client/src/pages/TripPlannerPage.tsx
index b8b5dc503..abecfdc50 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<boolean>(false)
const [editingReservation, setEditingReservation] = useState<Reservation | null>(null)
const [fitKey, setFitKey] = useState<number>(0)
+ const initialFitTripId = useRef<number | null>(null)
const [mobileSidebarOpen, setMobileSidebarOpen] = useState<'left' | 'right' | null>(null)
const [deletePlaceId, setDeletePlaceId] = useState<number | null>(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<number[]>(() => {
if (typeof window === 'undefined' || !connectionsStorageKey) return []