diff --git a/src/api/useVehicleLocations.ts b/src/api/useVehicleLocations.ts index 309c6f71..24678ae8 100644 --- a/src/api/useVehicleLocations.ts +++ b/src/api/useVehicleLocations.ts @@ -39,20 +39,40 @@ const loadedLocations = new Map< * it also caches the data, so if the same interval is requested again, it will not load it again. */ class LocationObservable { - constructor({ from, to, lineRef }: { from: Dateable; to: Dateable; lineRef?: number }) { - this.#loadData({ from, to, lineRef }) + constructor({ + from, + to, + lineRef, + operatorRef, + }: { + from: Dateable + to: Dateable + lineRef?: number + operatorRef?: number + }) { + this.#loadData({ from, to, lineRef, operatorRef }) } data: VehicleLocation[] = [] loading = true - async #loadData({ from, to, lineRef }: { from: Dateable; to: Dateable; lineRef?: number }) { + async #loadData({ + from, + to, + lineRef, + operatorRef, + }: { + from: Dateable + to: Dateable + lineRef?: number + operatorRef?: number + }) { let offset = 0 for (let i = 1; this.loading; i++) { let url = config.apiUrl url += `&${config.fromField}=${formatTime(from)}&${config.toField}=${formatTime(to)}&limit=${ config.limit * i - }&offset=${offset}` + }&offset=${offset}&siri_routes__operator_ref=${operatorRef}` if (lineRef) url += `&${config.lineRefField}=${lineRef}` const response = await fetchWithQueue(url) @@ -109,15 +129,17 @@ function getLocations({ to, lineRef, onUpdate, + operatorRef, }: { from: Dateable to: Dateable lineRef?: number + operatorRef?: number onUpdate: (locations: VehicleLocation[] | { finished: true }) => void // the observer will be called every time with all the locations that were loaded }) { const key = `${formatTime(from)}-${formatTime(to)}` if (!loadedLocations.has(key)) { - loadedLocations.set(key, new LocationObservable({ from, to, lineRef })) + loadedLocations.set(key, new LocationObservable({ from, to, lineRef, operatorRef })) } const observable = loadedLocations.get(key)! return observable.observe(onUpdate) @@ -139,11 +161,13 @@ export default function useVehicleLocations({ from, to, lineRef, + operatorRef, splitMinutes: split = 1, }: { from: Dateable to: Dateable lineRef?: number + operatorRef?: number splitMinutes?: false | number }) { const [locations, setLocations] = useState([]) @@ -156,6 +180,7 @@ export default function useVehicleLocations({ from, to, lineRef, + operatorRef, onUpdate: (data) => { if ('finished' in data) { setIsLoading((prev) => {