diff --git a/src/api/useVehicleLocations.ts b/src/api/useVehicleLocations.ts index 309c6f71..accf5f8e 100644 --- a/src/api/useVehicleLocations.ts +++ b/src/api/useVehicleLocations.ts @@ -5,7 +5,7 @@ */ import _ from 'lodash' -import moment, { Moment } from 'moment' +import moment from 'moment' import { useEffect, useState } from 'react' import { VehicleLocation } from 'src/model/vehicleLocation' @@ -17,7 +17,7 @@ const config = { lineRefField: 'siri_routes__line_ref', } as const -type Dateable = Date | number | string | Moment +type Dateable = Date | number | string function formatTime(time: Dateable) { if (moment.isMoment(time)) { @@ -132,7 +132,8 @@ function getMinutesInRange(from: Dateable, to: Dateable, gap = 1) { from: start.clone().add(i * gap, 'minutes'), to: start.clone().add((i + 1) * gap, 'minutes'), })) - return minutes + + return minutes.map((range) => ({ from: range.from.toDate(), to: range.to.toDate() })) //TODO getLocations() not work properly with moment } export default function useVehicleLocations({ @@ -185,5 +186,3 @@ export default function useVehicleLocations({ isLoading: isLoading.some((loading) => loading), } } - -export {} diff --git a/src/pages/RealtimeMapPage.tsx b/src/pages/RealtimeMapPage.tsx index 2084d9ce..68c18a85 100644 --- a/src/pages/RealtimeMapPage.tsx +++ b/src/pages/RealtimeMapPage.tsx @@ -59,8 +59,8 @@ export default function RealtimeMapPage() { const [to, setTo] = useState(fourMinutesAgo) const { locations, isLoading } = useVehicleLocations({ - from, - to, + from: from.toDate(), + to: to.toDate(), }) const loaded = locations.length @@ -205,14 +205,14 @@ export function Markers({ positions }: { positions: Point[] }) { return ( <> - {positions.map((pos) => ( + {positions.map((pos, i) => ( agency.operator_ref === pos.operator)?.agency_name, })} - key={pos.point?.id}> + key={i}>
{JSON.stringify(pos, null, 2)}
diff --git a/src/pages/SingleLineMapPage.tsx b/src/pages/SingleLineMapPage.tsx index 39322910..edb780ec 100644 --- a/src/pages/SingleLineMapPage.tsx +++ b/src/pages/SingleLineMapPage.tsx @@ -63,8 +63,8 @@ const SingleLineMapPage = () => { const selectedRouteIds = selectedRoute?.routeIds const { locations, isLoading: locationsIsLoading } = useVehicleLocations({ - from: selectedRouteIds ? +new Date(timestamp).setHours(0, 0, 0, 0) : 0, - to: selectedRouteIds ? +new Date(timestamp).setHours(23, 59, 59, 999) : 0, + from: selectedRouteIds ? new Date(timestamp).setHours(0, 0, 0, 0) : 0, + to: selectedRouteIds ? new Date(timestamp).setHours(23, 59, 59, 999) : 0, lineRef: selectedRoute?.lineRef ?? 0, splitMinutes: 20, })