updats on the dispatch page

This commit is contained in:
2026-09-10 17:57:00 +05:30
parent 79a8f2b234
commit 8b2c4daef8
34 changed files with 6929 additions and 1059 deletions

View File

@@ -18,6 +18,7 @@ import { stockApi, type StockRequestQuery } from '@/api/stock';
import { tenantsApi, utilsApi, type TenantListQuery } from '@/api/tenants';
import { partnersApi } from '@/api/deliveries';
import { customersApi, type CustomerQuery } from '@/api/customers';
import { telemetryApi, type RiderSnapshot } from '@/api/telemetry';
import { uploadsApi } from '@/api/uploads';
import { APP_BROWSE_CATEGORY } from '@/features/catalogue/tenantCategories';
import { queryKeys } from './keys';
@@ -618,3 +619,53 @@ export function usePartners(applocationid: number | undefined) {
...stable,
});
}
/**
* Live positions for a set of riders.
*
* ── Fanned out, because there is no fleet form ────────────────────────────
*
* `getriderperiodiclogs` answers for one rider at a time. A merchant's round is
* a handful of riders, so a handful of requests every fifteen seconds is
* cheap — and the fan-out means one rider's failure does not blank the others,
* which a single fleet call would.
*
* ── Fifteen seconds, matching the source ──────────────────────────────────
*
* The rider app reports every twenty seconds or so, so polling faster only
* re-reads the same fix. Fifteen keeps the board a beat ahead of the data
* without asking for anything that does not exist yet.
*
* Paused when the tab is hidden: nobody is watching a map they cannot see, and
* a background tab polling a third-party service all afternoon is rude.
*/
export function useRiderLive(userids: readonly number[], isEnabled = true) {
const ids = [...new Set(userids)].filter((id) => id > 0);
const results = useQueries({
queries: ids.map((userid) => ({
queryKey: queryKeys.live.rider(userid),
queryFn: ({ signal }: { signal: AbortSignal }) => telemetryApi.rider(userid, signal),
enabled: isEnabled,
refetchInterval: isEnabled ? 15_000 : false,
refetchIntervalInBackground: false,
// A stale fix is worth drawing while the next one is fetched; blanking
// the map every fifteen seconds would make it unreadable.
staleTime: 10_000,
retry: 1,
})),
});
const byRider = new Map<number, RiderSnapshot | null>();
results.forEach((result, index) => {
const id = ids[index];
if (id !== undefined) byRider.set(id, result.data ?? null);
});
return {
data: byRider,
isLoading: results.some((result) => result.isLoading),
/** True while any rider is being re-read — for a quiet "updating" hint. */
isFetching: results.some((result) => result.isFetching),
};
}