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(journey): keep page mounted during in-place journey refetch

jubnl75d23eb6aaa5
diff --git a/client/src/store/journeyStore.test.ts b/client/src/store/journeyStore.test.ts
index 7b1f6760a..564969ec2 100644
--- a/client/src/store/journeyStore.test.ts
+++ b/client/src/store/journeyStore.test.ts
@@ -314,6 +314,47 @@ describe('journeyStore', () => {
expect(storedEntry?.photos[0].id).toBe(201);
});
+ // ── loadJourney silent refresh ───────────────────────────────────────────
+
+ it('FE-STORE-JOURNEY-016: loadJourney does not set loading when refreshing same journey', async () => {
+ const existing = buildJourneyDetail({ id: 5, title: 'Old' });
+ useJourneyStore.setState({ current: existing, loading: false });
+
+ const loadingValues: boolean[] = [];
+ const unsub = useJourneyStore.subscribe(s => loadingValues.push(s.loading));
+
+ const refreshed = buildJourneyDetail({ id: 5, title: 'Refreshed' });
+ server.use(
+ http.get('/api/journeys/5', () => HttpResponse.json(refreshed))
+ );
+
+ await useJourneyStore.getState().loadJourney(5);
+ unsub();
+
+ expect(loadingValues.every(v => v === false)).toBe(true);
+ expect(useJourneyStore.getState().current?.title).toBe('Refreshed');
+ });
+
+ it('FE-STORE-JOURNEY-017: loadJourney sets loading on cold load (different journey)', async () => {
+ const existing = buildJourneyDetail({ id: 5 });
+ useJourneyStore.setState({ current: existing, loading: false });
+
+ const loadingValues: boolean[] = [];
+ const unsub = useJourneyStore.subscribe(s => loadingValues.push(s.loading));
+
+ const other = buildJourneyDetail({ id: 99 });
+ server.use(
+ http.get('/api/journeys/99', () => HttpResponse.json(other))
+ );
+
+ await useJourneyStore.getState().loadJourney(99);
+ unsub();
+
+ expect(loadingValues).toContain(true);
+ expect(useJourneyStore.getState().current?.id).toBe(99);
+ expect(useJourneyStore.getState().loading).toBe(false);
+ });
+
// ── clear ────────────────────────────────────────────────────────────────
it('FE-STORE-JOURNEY-015: clear resets state', () => {
diff --git a/client/src/store/journeyStore.ts b/client/src/store/journeyStore.ts
index e0a8f22bb..c0464133c 100644
--- a/client/src/store/journeyStore.ts
+++ b/client/src/store/journeyStore.ts
@@ -124,7 +124,8 @@ export const useJourneyStore = create<JourneyState>((set, get) => ({
},
loadJourney: async (id) => {
- set({ loading: true, notFound: false })
+ const cold = get().current?.id !== id
+ if (cold) set({ loading: true, notFound: false })
try {
const data = await journeyApi.get(id)
set({ current: data })
@@ -134,7 +135,7 @@ export const useJourneyStore = create<JourneyState>((set, get) => ({
}
throw err
} finally {
- set({ loading: false })
+ if (cold) set({ loading: false })
}
},