Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "perf: useVehicleLocations usage" #126

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/api/useVehicleLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)) {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -185,5 +186,3 @@ export default function useVehicleLocations({
isLoading: isLoading.some((loading) => loading),
}
}

export {}
8 changes: 4 additions & 4 deletions src/pages/RealtimeMapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -205,14 +205,14 @@ export function Markers({ positions }: { positions: Point[] }) {
return (
<>
<MarkerClusterGroup chunkedLoading iconCreateFunction={createClusterCustomIcon}>
{positions.map((pos) => (
{positions.map((pos, i) => (
<Marker
position={pos.loc}
icon={busIcon({
operator_id: pos.operator?.toString() || 'default',
name: agencyList.find((agency) => agency.operator_ref === pos.operator)?.agency_name,
})}
key={pos.point?.id}>
key={i}>
<Popup>
<pre>{JSON.stringify(pos, null, 2)}</pre>
</Popup>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SingleLineMapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
Loading