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.

fix(map): set the trip overview aside for the visit instead of switching it off

Mauricefef7ac4587e0
diff --git a/client/src/components/Map/useTripRouteOverview.ts b/client/src/components/Map/useTripRouteOverview.ts
index fff6d9d3f..61b20745a 100644
--- a/client/src/components/Map/useTripRouteOverview.ts
+++ b/client/src/components/Map/useTripRouteOverview.ts
@@ -17,6 +17,9 @@ export interface TripRouteOverview extends TripRouteSummary {
loading: boolean
}
+/** The overview as the planner reads it: also whether the trip has any stop to route at all. */
+type PlannedTripRouteOverview = TripRouteOverview & { hasPlannedRoute: boolean }
+
const EMPTY: TripRouteOverview = { ...summariseTripRoute([]), loading: false }
const EMPTY_PLACES: Place[] = []
@@ -49,7 +52,7 @@ export function useTripRouteOverview(
vias?: TripRouteVias,
/** MDT-02: where the stages of the trip's multi-day tours run, so a day holding one draws that stage. */
tourStageStops?: TourStageStops,
-) {
+): PlannedTripRouteOverview {
const optimizeFromAccommodation = useSettingsStore(s => s.settings.optimize_from_accommodation)
const toursEnabled = useTripAddonEnabled(tripId, 'tours')
// Leg text is formatted at compute time, so a km↔mi switch has to re-run (#1300).
diff --git a/client/src/pages/tripPlanner/useTripPlanner.overview.test.tsx b/client/src/pages/tripPlanner/useTripPlanner.overview.test.tsx
index 438012158..bb6153eaa 100644
--- a/client/src/pages/tripPlanner/useTripPlanner.overview.test.tsx
+++ b/client/src/pages/tripPlanner/useTripPlanner.overview.test.tsx
@@ -115,4 +115,27 @@ describe('useTripPlanner: showing the whole trip', () => {
});
expect(result.current.overviewActive).toBe(false);
});
+
+ it('puts the overview away for this visit only, the remembered switch stays on and the pill brings it back', async () => {
+ const { result } = await renderPlanner({ selectedDayId: day.id });
+ const remembered = () => useSettingsStore.getState().settings.planner_trip_views?.['42']?.overview;
+
+ act(() => {
+ result.current.toggleOverview();
+ });
+ expect(remembered()).toBe(true);
+ act(() => {
+ result.current.hideOverview();
+ });
+ expect(result.current.overviewShown).toBe(false);
+ expect(result.current.overviewActive).toBe(false);
+ expect(remembered()).toBe(true);
+
+ act(() => {
+ result.current.toggleOverview();
+ });
+ expect(result.current.overviewShown).toBe(true);
+ expect(result.current.overviewActive).toBe(true);
+ expect(remembered()).toBe(true);
+ });
});
diff --git a/client/src/pages/tripPlanner/useTripPlanner.ts b/client/src/pages/tripPlanner/useTripPlanner.ts
index eca3c1695..83cf734b4 100644
--- a/client/src/pages/tripPlanner/useTripPlanner.ts
+++ b/client/src/pages/tripPlanner/useTripPlanner.ts
@@ -370,22 +370,27 @@ export function useTripPlanner() {
} = plannerDialogs
const {
mapLocked, toggleMapLocked, mapLockedRef, isMobileRef, fitKey, setFitKey,
- overviewShown, toggleOverview: toggleMapOverview, dawarichTrailShown, toggleDawarichTrail, dawarichTrail,
+ overviewShown: overviewRemembered, toggleOverview: toggleMapOverview, dawarichTrailShown, toggleDawarichTrail, dawarichTrail,
routeShown, setRouteShown, autoShowRoute, transitRoutesShown, routeProfile, setRouteProfile,
} = usePlannerMapView({ tripId, trip, places, selectedDayId, isMobile })
+ // Making room for the day details puts the overview away for this visit only:
+ // the switch the account remembers stays on, and the pill brings it back.
+ const [overviewSetAsideFor, setOverviewSetAsideFor] = useState<number | null>(null)
+ const overviewShown = overviewRemembered && overviewSetAsideFor !== tripId
// Road trip mode draws its own overview.
const overviewActive = overviewShown && !roadtripMode
const hideOverview = useCallback(() => {
- if (overviewActive) toggleMapOverview()
- }, [overviewActive, toggleMapOverview])
+ if (overviewActive) setOverviewSetAsideFor(tripId)
+ }, [overviewActive, tripId])
const setShowDayDetail = useCallback((day: Day | null) => {
stashedDayDetailRef.current = null
setDayDetail(day)
}, [])
const toggleOverview = useCallback(() => {
if (!overviewShown) stashedDayDetailRef.current = null
- toggleMapOverview()
- }, [overviewShown, toggleMapOverview])
+ if (overviewRemembered && !overviewShown) setOverviewSetAsideFor(null)
+ else toggleMapOverview()
+ }, [overviewShown, overviewRemembered, toggleMapOverview])
const [mobileSidebarOpen, setMobileSidebarOpen] = useState<'left' | 'right' | null>(null)
const mobilePlanScrollTopRef = useRef<number>(0)
const mobilePlacesScrollTopRef = useRef<number>(0)