mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user