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(planner): treat the trip opened before as still loading when another one opens

Maurice4fd8f3987f44
diff --git a/client/src/pages/tripPlanner/useTripPlanner.tabLink.test.tsx b/client/src/pages/tripPlanner/useTripPlanner.tabLink.test.tsx
index 26e1a93e3..6be921d02 100644
--- a/client/src/pages/tripPlanner/useTripPlanner.tabLink.test.tsx
+++ b/client/src/pages/tripPlanner/useTripPlanner.tabLink.test.tsx
@@ -1,4 +1,4 @@
-// FE-TP-TABLINK-001
+// FE-TP-TABLINK-001, FE-TP-OPEN-001
import { act, renderHook, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
@@ -108,3 +108,16 @@ describe('useTripPlanner — ?tab= while the planner is open', () => {
expect(sessionStorage.getItem('trip-tab-42')).toBe('collab');
});
});
+
+describe('useTripPlanner: opening another trip', () => {
+ it('FE-TP-OPEN-001: the trip still held from the one opened before counts as loading, not as this one', async () => {
+ useTripStore.setState({ trip: buildTrip({ id: 7, title: 'Rome' }), isLoading: false });
+ const { result } = renderHook(() => useTripPlanner(), { wrapper });
+ expect(result.current.isLoading).toBe(true);
+ await act(async () => {
+ await Promise.resolve();
+ });
+ act(() => useTripStore.setState({ trip: buildTrip({ id: 42, title: 'Kyoto' }) }));
+ expect(result.current.isLoading).toBe(false);
+ });
+});
diff --git a/client/src/pages/tripPlanner/useTripPlanner.ts b/client/src/pages/tripPlanner/useTripPlanner.ts
index d0bfd516d..80b87818f 100644
--- a/client/src/pages/tripPlanner/useTripPlanner.ts
+++ b/client/src/pages/tripPlanner/useTripPlanner.ts
@@ -724,10 +724,14 @@ export function useTripPlanner() {
return () => clearTimeout(timer)
}, [isLoading])
+ // The store still holds the trip opened before until loadTrip runs after the first
+ // render, so that trip counts as loading too rather than showing under this one's id.
+ const opening = isLoading || (trip != null && trip.id !== tripId)
+
return {
tripId, navigate, toast, t, language, locale, settings, placesPhotosEnabled,
trip, days, places, assignments, storedAssignments, packingItems, todoItems, categories, reservations, budgetItems, files,
- selectedDayId, isLoading, tripActions, can, canUploadFiles,
+ selectedDayId, isLoading: opening, tripActions, can, canUploadFiles,
pushUndo, undo, canUndo, lastActionLabel, handleUndo,
enabledAddons, collabFeatures, journalId: journal.openJournalId, tripAccommodations, setTripAccommodations,
roadtripMode, toggleRoadtripMode, roadtripActive, roadtripFeedActive, roadtripRoutes, roadtripLineColors, roadtripMapLines, roadtripMapPlaces, collapsedRoadtripDays, toggleRoadtripDay, roadtripCorridor,