fix(ci): presence through the sessions domain, warm bags taken once, a slimmer planner page

Server lint: the realtime gateway injected the user_sessions repository, a table the sessions domain owns; it now asks SessionsService. The presence tests reuse the handshake's gateway instead of building one more by hand (test-new-service ratchet).

Client tests: the packing bags kept per trip leaked from one test (and one list) into the next; bags read ahead are now taken once as the list's first state, and only while bag tracking is on. The planner hook hands the page planMapKept, tourMapKept and the tour stage's class, so page tests that mock the hook keep working and TripPlannerPage is back at its size baseline (1127); the B4A wiring test reads the new condition.

Client lint: max-depth in src is down to 19, the baseline follows; the new websocket tests call onopen with ?. instead of a non-null assertion.
This commit is contained in:
Maurice
2026-11-29 10:13:53 +01:00
parent 5401728c41
commit 10ad92574d
9 changed files with 45 additions and 42 deletions
+2 -2
View File
@@ -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')
+17 -16
View File
@@ -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<number, { bags: PackingBag[]; unassigned: number | null }>();
const warmBags = new Map<number, { bags: PackingBag[]; unassigned: number | null }>();
/** 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<void> {
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<PackingBag[]>(() => keptBags.get(tripId)?.bags ?? []);
const [warm] = useState(() => takeWarmBags(tripId, bagTrackingEnabled));
const [bags, setBags] = useState<PackingBag[]>(warm.bags);
/** Server-summed weight of everything in no bag (#2191); null until the first load. */
const [unassignedWeightGrams, setUnassignedWeightGrams] = useState<number | null>(
() => 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<number | null>(warm.unassigned);
const reloadBags = useCallback(async () => {
if (!bagTrackingEnabled) return;
+5 -8
View File
@@ -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. */}
<TripWarningsBanner tripId={tripId} onOpenPluginTab={(pid) => 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)) && (
<div style={{ position: 'absolute', inset: 0, visibility: activeTab === 'plan' ? undefined : 'hidden' }}>
{(activeTab === 'plan' || planMapKept) && (
<div className={activeTab === 'plan' ? undefined : 'invisible'} style={{ position: 'absolute', inset: 0 }}>
<PlanMapStage
tripId={tripId} trip={trip} can={can} days={days} places={places} reservations={reservations} isMobile={isMobile}
selectedDayId={selectedDayId} selectedPlaceId={selectedPlaceId} selectedPlace={selectedPlace} showDayDetail={showDayDetail} handleSelectDay={handleSelectDay}
@@ -620,8 +617,8 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
</div>
)}
{(activeTab === 'tour-planner' || keptMapTabs.has('tour-planner')) && enabledAddons.tours && !isMobile && (
<TourGpxDropZone gpxImport={tourGpxImport} canEdit={canPlaceEdit} className={activeTab === 'tour-planner' ? 'absolute inset-0' : 'invisible absolute inset-0'}>
{(activeTab === 'tour-planner' || tourMapKept) && enabledAddons.tours && !isMobile && (
<TourGpxDropZone gpxImport={tourGpxImport} canEdit={canPlaceEdit} className={tourStageClass}>
<TourPlannerMapStage
tripId={tripId} mapTileUrl={mapTileUrl} leftHidden={leftHidden} rightHidden={rightHidden} t={t}
tourPlanner={tourPlanner} tourMap={tourMap} locationSearch={locationSearch} canPlaceEdit={canPlaceEdit}
@@ -105,7 +105,7 @@ test('B4A Tours tab is readable, desktop-only off a large screen, and absent wit
assert.match(branch.whenTrue.getText(hook), /desktopOnly: tourTab\.desktopOnly/)
assert.doesNotMatch(tabs.getText(hook), /\bcan\b|canPlaceEdit|canDayEdit/)
assert.match(hookText, /!validTabIds\.includes\(activeTab\)[\s\S]*?setActiveTab\('plan'\)/)
assert.match(pageText, /activeTab === 'tour-planner' && enabledAddons\.tours && !isMobile/)
assert.match(pageText, /\(activeTab === 'tour-planner' \|\| tourMapKept\) && enabledAddons\.tours && !isMobile/)
// The app counts as a phone shell on an iPad too: the workspace follows its tab, not the phone test.
assert.equal(initializer(workspace, 'workspaceUp').getText(workspace), "activeTab === 'tour-planner' && (!isMobile || largeTouch)")
assert.doesNotMatch(workspaceText, /!isMobile(?! \|\| largeTouch)/)
@@ -783,7 +783,10 @@ export function useTripPlanner() {
dawarichTrailShown, toggleDawarichTrail, dawarichTrail, dawarichHiddenDates, dawarichEnabled: !!enabledAddons.dawarich,
followTrack, roadtripViaCounts,
allowedFileTypes, tripMembers, setTripMembers, refreshMembers, loadAccommodations,
TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange, keptMapTabs, tabLink,
TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange, tabLink,
// Not on a narrow screen, where the plan tab portals its own controls over the page.
planMapKept: keptMapTabs.has('plan') && !isMobile, tourMapKept: keptMapTabs.has('tour-planner'),
tourStageClass: activeTab === 'tour-planner' ? 'absolute inset-0' : 'invisible absolute inset-0',
leftWidth, rightWidth, viewportWidth, leftCollapsed, rightCollapsed, setLeftCollapsed, setRightCollapsed,
leftHidden, rightHidden, toggleLeft, toggleRight, narrowPanels,
startResizeLeft, startResizeRight, nudgeLeft, nudgeRight, resizing, resizeMin, resizeMaxLeft, resizeMaxRight,