updates
This commit is contained in:
@@ -1606,9 +1606,10 @@ const Dispatch = ({
|
||||
: riders,
|
||||
[isAllActiveView, riders, activeOrderRiderIdSet]
|
||||
);
|
||||
// Active section sidebar riders — built from the FULL day's unfiltered rows
|
||||
// (liveRows, all batches, no GPS-status gate). Uses a sticky cache so cards
|
||||
// only disappear when the API returns an explicit terminal status (delivered /
|
||||
// Active section sidebar riders — built from the currently selected batch's
|
||||
// rows (filteredLiveRows), so switching to e.g. "Afternoon Batch" doesn't
|
||||
// keep showing morning-batch orders. Uses a sticky cache so cards only
|
||||
// disappear when the API returns an explicit terminal status (delivered /
|
||||
// cancelled / skipped). Temporary row omissions during the 15-second poll
|
||||
// cycle (single-page refetch, brief API inconsistency) no longer cause cards
|
||||
// to flash away and reappear.
|
||||
@@ -1620,7 +1621,7 @@ const Dispatch = ({
|
||||
|
||||
const TERMINAL = new Set(['delivered', 'cancelled', 'skipped', 'complete', 'completed']);
|
||||
|
||||
liveRows.forEach((o) => {
|
||||
filteredLiveRows.forEach((o) => {
|
||||
const id = String(o.orderid);
|
||||
const s = String(o.orderstatus || '').toLowerCase();
|
||||
if (s === 'active') {
|
||||
@@ -1653,7 +1654,7 @@ const Dispatch = ({
|
||||
}
|
||||
});
|
||||
return Object.values(byRider);
|
||||
}, [isAllActiveView, liveRows, riders]);
|
||||
}, [isAllActiveView, filteredLiveRows, riders]);
|
||||
// Live GPS coordinates of exactly the riders this view shows (active + has an
|
||||
// order), fed to MapController's auto-fit so the map frames what's rendered.
|
||||
const allViewLivePoints = useMemo(
|
||||
@@ -1666,11 +1667,13 @@ const Dispatch = ({
|
||||
[isAllActiveView, liveRiderLocations, activeOrderRiderIdSet]
|
||||
);
|
||||
|
||||
// Clear the sticky Active-view cache when the operator switches date or hub —
|
||||
// otherwise cards from a previously viewed day/location could linger.
|
||||
// Clear the sticky Active-view cache when the operator switches date, hub, or
|
||||
// batch — otherwise cards from a previously viewed day/location/batch (e.g.
|
||||
// Morning Batch orders still marked "active") could linger after switching
|
||||
// to Afternoon Batch.
|
||||
useEffect(() => {
|
||||
stickyActiveRef.current = {};
|
||||
}, [selectedDate, selectedAppLocationId]);
|
||||
}, [selectedDate, selectedAppLocationId, selectedBatch, selectedTimeField]);
|
||||
|
||||
// Per-rider canvas renderer for the actual (right) map in Compare mode.
|
||||
// Single setter used by every interactive site in the UI. In uncontrolled mode it
|
||||
@@ -1752,14 +1755,15 @@ const Dispatch = ({
|
||||
}
|
||||
// "All Active Routes": the header must reflect exactly what the list/map
|
||||
// shows — the in-progress orders and the riders working them — NOT the whole
|
||||
// day's totals. We count only active deliveries (and `visibleRiders`, which
|
||||
// is already gated to active-order riders) so the tiles can't disagree with
|
||||
// the list/map below.
|
||||
// day's totals. Derived from `activeViewRiders` (the same sticky-cached data
|
||||
// the sidebar list below renders) instead of the GPS-status-gated
|
||||
// allViewOrders/visibleRiders, which could disagree with the list and read
|
||||
// 0 even while riders/orders are visible below.
|
||||
if (isAllActiveView) {
|
||||
const activeOrders = allViewOrders.filter((o) => String(o?.orderstatus || '').toLowerCase() === 'active');
|
||||
const activeOrders = activeViewRiders.flatMap((r) => r.orders);
|
||||
return {
|
||||
orders: activeOrders.length,
|
||||
riders: visibleRiders.length,
|
||||
riders: activeViewRiders.length,
|
||||
km: activeOrders.reduce((s, o) => s + parseFloat(o.actualkms || o.kms || 0), 0),
|
||||
profit: activeOrders.reduce((s, o) => s + parseFloat(o.profit || 0), 0),
|
||||
label: 'Active Fleet'
|
||||
@@ -1772,7 +1776,7 @@ const Dispatch = ({
|
||||
profit: stats.totalProfit,
|
||||
label: 'Total Fleet'
|
||||
};
|
||||
}, [focusedRider, focusedKitchen, isAllActiveView, allViewOrders, visibleRiders, stats]);
|
||||
}, [focusedRider, focusedKitchen, isAllActiveView, activeViewRiders, stats]);
|
||||
|
||||
// Count of in-progress deliveries shown in the Active view list. Derives from
|
||||
// the sticky cache (via activeViewRiders) so header and card list always agree.
|
||||
@@ -4605,6 +4609,7 @@ const Dispatch = ({
|
||||
<ActiveSection
|
||||
visibleRiders={activeViewRiders}
|
||||
riders={riders}
|
||||
resetKey={`${selectedDate}|${selectedAppLocationId}|${selectedBatch}`}
|
||||
focusedStop={focusedStop}
|
||||
handleRiderFocus={handleRiderFocus}
|
||||
setFocusedStop={setFocusedStop}
|
||||
|
||||
Reference in New Issue
Block a user