diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json index 54b332ecf..dd3d0b650 100644 --- a/client/scripts/eslint-baseline.json +++ b/client/scripts/eslint-baseline.json @@ -22,7 +22,7 @@ "trek/no-window-globals": 41, "react-refresh/only-export-components": 44, "unused-disable-directive": 5, - "max-depth": 21, + "max-depth": 19, "react-hooks/void-use-memo": 1, "@typescript-eslint/no-unused-expressions": 2, "react-hooks/purity": 1, diff --git a/client/src/api/websocket.extra.test.ts b/client/src/api/websocket.extra.test.ts index bc7873482..a8be04072 100644 --- a/client/src/api/websocket.extra.test.ts +++ b/client/src/api/websocket.extra.test.ts @@ -164,7 +164,7 @@ describe('websocket > presence', () => { it('FE-WSCORE-017: tells the server on open and on every change whether the tab is in front', async () => { Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => 'visible' }) const sock = await openSocket() - sock.onopen!() + sock.onopen?.() setVisibility('hidden') setVisibility('visible') @@ -173,7 +173,7 @@ describe('websocket > presence', () => { it('FE-WSCORE-018: stops telling it once logged out', async () => { const sock = await openSocket() - sock.onopen!() + sock.onopen?.() disconnect() setVisibility('hidden') diff --git a/client/src/components/Packing/usePackingBags.ts b/client/src/components/Packing/usePackingBags.ts index 936978148..17ff74835 100644 --- a/client/src/components/Packing/usePackingBags.ts +++ b/client/src/components/Packing/usePackingBags.ts @@ -14,17 +14,24 @@ interface Toaster { } /** - * The last bags read per trip in this tab. A list opened again, or opened after - * the trip read them ahead (warmPackingBags), starts with them instead of - * drawing the list first and the bag sidebar a moment later; the read that - * follows only refreshes them. + * Bags a trip read ahead while it sat open (warmPackingBags), waiting for the + * packing list to open. The list takes them once as its first state, so it + * opens with its bag sidebar in place instead of drawing it a moment later; + * its own read follows and refreshes them. Taken, not kept: a list opened + * later reads afresh rather than starting from an old answer. */ -const keptBags = new Map(); +const warmBags = new Map(); -/** Reads a trip's bags ahead, while it sits open, for the list to start with. */ +/** Reads a trip's bags ahead, while it sits open, for the packing list to start with. */ export async function warmPackingBags(tripId: number): Promise { const r = await packingApi.listBags(tripId); - keptBags.set(tripId, { bags: r.bags || [], unassigned: r.unassigned_weight_grams ?? null }); + warmBags.set(tripId, { bags: r.bags || [], unassigned: r.unassigned_weight_grams ?? null }); +} + +function takeWarmBags(tripId: number, enabled: boolean): { bags: PackingBag[]; unassigned: number | null } { + const warm = enabled ? warmBags.get(tripId) : undefined; + warmBags.delete(tripId); + return warm ?? { bags: [], unassigned: null }; } /** @@ -43,16 +50,10 @@ export function usePackingBags({ t: Translate; toast: Toaster; }) { - const [bags, setBags] = useState(() => keptBags.get(tripId)?.bags ?? []); + const [warm] = useState(() => takeWarmBags(tripId, bagTrackingEnabled)); + const [bags, setBags] = useState(warm.bags); /** Server-summed weight of everything in no bag (#2191); null until the first load. */ - const [unassignedWeightGrams, setUnassignedWeightGrams] = useState( - () => keptBags.get(tripId)?.unassigned ?? null - ); - - // What the list shows now is what it starts with next time. - useEffect(() => { - keptBags.set(tripId, { bags, unassigned: unassignedWeightGrams }); - }, [tripId, bags, unassignedWeightGrams]); + const [unassignedWeightGrams, setUnassignedWeightGrams] = useState(warm.unassigned); const reloadBags = useCallback(async () => { if (!bagTrackingEnabled) return; diff --git a/client/src/pages/TripPlannerPage.tsx b/client/src/pages/TripPlannerPage.tsx index c6c50131f..7ad56157b 100644 --- a/client/src/pages/TripPlannerPage.tsx +++ b/client/src/pages/TripPlannerPage.tsx @@ -73,7 +73,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null { dawarichEnabled, dawarichTrailShown, toggleDawarichTrail, dawarichTrail, dawarichHiddenDates, followTrack, roadtripViaCounts, allowedFileTypes, tripMembers, setTripMembers, refreshMembers, loadAccommodations, - TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange, keptMapTabs, + TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange, planMapKept, tourMapKept, tourStageClass, leftWidth, rightWidth, leftHidden, rightHidden, toggleLeft, toggleRight, startResizeLeft, startResizeRight, nudgeLeft, nudgeRight, resizing, resizeMin, resizeMaxLeft, resizeMaxRight, @@ -259,11 +259,8 @@ function TripPlannerPageDesktop(): React.ReactElement | null { plugins with a tab here, floating bottom overlay for the rest. */} handleTabChange(`plugin:${pid}`)} /> - {/* Plan and the tour planner each keep their map once opened, hidden while - another tab shows, so switching back does not start a map again. Not on - a narrow screen, where the plan tab puts its own controls over the page. */} - {(activeTab === 'plan' || (keptMapTabs.has('plan') && !isMobile)) && ( -
+ {(activeTab === 'plan' || planMapKept) && ( +
)} - {(activeTab === 'tour-planner' || keptMapTabs.has('tour-planner')) && enabledAddons.tours && !isMobile && ( - + {(activeTab === 'tour-planner' || tourMapKept) && enabledAddons.tours && !isMobile && ( + undefined); -const sessions = { touchLastSeen } as unknown as UserSessionsRepository; +const sessions = { touchLastSeen } as unknown as SessionsService; const consumeWithMeta = vi.fn(); const tokens = { consumeWithMeta } as unknown as EphemeralTokenService; @@ -741,7 +741,8 @@ describe('book rooms with unusable sockets in them', () => { * its session's last activity current without any request. */ describe('RealtimeGateway presence', () => { - const gateway = () => new RealtimeGateway(new TripAccessService(db), tokens, journeys, users, appSettings, sessions); + // The gateway a handshake built; its own socket stays out of the server's client list. + const gateway = async () => (await connect('/ws?token=x')).gw; it('WSGW-PRES-001: a tab in the background is not online, one in front is, one that never said is', async () => { const hidden = socket(); @@ -751,7 +752,7 @@ describe('RealtimeGateway presence', () => { registerSocket(front, { id: 12, username: 'f' } as User); registerSocket(silent, { id: 13, username: 's' } as User); setServer({ clients: new Set([hidden, front, silent]) } as never); - const gw = gateway(); + const gw = await gateway(); await gw.handlePresence({ visible: false }, hidden); await gw.handlePresence({ visible: true }, front); @@ -765,7 +766,7 @@ describe('RealtimeGateway presence', () => { vi.setSystemTime(new Date('2026-11-29T09:00:00Z')); const ws = socket(); registerSocket(ws, { id: 14, username: 'p' } as User, 'sess-p'); - const gw = gateway(); + const gw = await gateway(); await gw.handlePresence({ visible: true }, ws); await gw.handlePresence({ visible: true }, ws); @@ -784,7 +785,7 @@ describe('RealtimeGateway presence', () => { const noSession = socket(); registerSocket(hidden, { id: 15, username: 'h' } as User, 'sess-h'); registerSocket(noSession, { id: 16, username: 'n' } as User); - const gw = gateway(); + const gw = await gateway(); await gw.handlePresence({ visible: false }, hidden); await gw.handlePresence({ visible: true }, noSession); @@ -800,7 +801,7 @@ describe('RealtimeGateway presence', () => { registerSocket(ws, { id: 17, username: 'b' } as User, 'sess-b'); setSocketVisible(ws, true); touchLastSeen.mockRejectedValueOnce(new Error('busy')); - const gw = gateway(); + const gw = await gateway(); gw.afterInit({ clients: new Set([ws]) } as never); await vi.advanceTimersByTimeAsync(30_000);