Skip to content

Commit

Permalink
Merge branch 'v3' into DT-6564
Browse files Browse the repository at this point in the history
  • Loading branch information
partisaani committed Dec 5, 2024
2 parents b205af9 + 441e3ee commit d82b56b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
31 changes: 20 additions & 11 deletions app/component/itinerary/navigator/NaviContainer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import distance from '@digitransit-search-util/digitransit-search-util-distance';
import PropTypes from 'prop-types';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { legTime } from '../../../util/legUtils';
import { checkPositioningPermission } from '../../../action/PositionActions';
import { legShape, relayShape } from '../../../util/shapes';
import NaviBottom from './NaviBottom';
import NaviCardContainer from './NaviCardContainer';
Expand All @@ -23,18 +24,26 @@ function NaviContainer(
},
{ getStore },
) {
const [isPositioningAllowed, setPositioningAllowed] = useState(false);

const position = getStore('PositionStore').getLocationState();

const {
realTimeLegs,
time,
isPositioningAllowed,
origin,
firstLeg,
lastLeg,
currentLeg,
nextLeg,
} = useRealtimeLegs(mapRef, relayEnvironment, legs);
const { realTimeLegs, time, origin, firstLeg, lastLeg, currentLeg, nextLeg } =
useRealtimeLegs(relayEnvironment, legs);

useEffect(() => {
if (position.hasLocation) {
mapRef?.enableMapTracking();
setPositioningAllowed(true);
} else {
checkPositioningPermission().then(permission => {
if (permission.state === 'granted') {
mapRef?.enableMapTracking();
setPositioningAllowed(true);
}
});
}
}, [mapRef]);

if (!realTimeLegs?.length) {
return null;
Expand Down
17 changes: 2 additions & 15 deletions app/component/itinerary/navigator/hooks/useRealtimeLegs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import polyUtil from 'polyline-encoded';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { fetchQuery } from 'react-relay';
import { checkPositioningPermission } from '../../../../action/PositionActions';
import { GeodeticToEcef, GeodeticToEnu } from '../../../../util/geo-utils';
import { legTime } from '../../../../util/legUtils';
import { epochToIso } from '../../../../util/timeUtils';
Expand Down Expand Up @@ -88,8 +87,7 @@ function matchLegEnds(legs) {
}
}

const useRealtimeLegs = (mapRef, relayEnvironment, initialLegs = []) => {
const [isPositioningAllowed, setPositioningAllowed] = useState(false);
const useRealtimeLegs = (relayEnvironment, initialLegs = []) => {
const [realTimeLegs, setRealTimeLegs] = useState();
const [time, setTime] = useState(Date.now());

Expand All @@ -98,15 +96,6 @@ const useRealtimeLegs = (mapRef, relayEnvironment, initialLegs = []) => {
[initialLegs[0]],
);

const enableMapTracking = useCallback(async () => {
const permission = await checkPositioningPermission();
const isPermissionGranted = permission.state === 'granted' || true;
if (isPermissionGranted) {
mapRef?.enableMapTracking();
}
setPositioningAllowed(isPermissionGranted);
}, [mapRef]);

const queryAndMapRealtimeLegs = useCallback(
async legs => {
if (!legs.length) {
Expand Down Expand Up @@ -173,7 +162,6 @@ const useRealtimeLegs = (mapRef, relayEnvironment, initialLegs = []) => {
}, [initialLegs, queryAndMapRealtimeLegs]);

useEffect(() => {
enableMapTracking();
fetchAndSetRealtimeLegs();

const interval = setInterval(() => {
Expand All @@ -182,7 +170,7 @@ const useRealtimeLegs = (mapRef, relayEnvironment, initialLegs = []) => {
}, 10000);

return () => clearInterval(interval);
}, [enableMapTracking, fetchAndSetRealtimeLegs]);
}, [fetchAndSetRealtimeLegs]);

let currentIndex = -1;

Expand All @@ -199,7 +187,6 @@ const useRealtimeLegs = (mapRef, relayEnvironment, initialLegs = []) => {
return {
realTimeLegs,
time,
isPositioningAllowed,
origin,
firstLeg: realTimeLegs?.[0],
lastLeg: realTimeLegs?.[realTimeLegs.length - 1],
Expand Down
2 changes: 1 addition & 1 deletion app/component/map/ItineraryPageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LocationMarker from './LocationMarker';
import MapWithTracking from './MapWithTracking';
import VehicleMarkerContainer from './VehicleMarkerContainer';

const POINT_FOCUS_ZOOM = 16; // default
const POINT_FOCUS_ZOOM = 17; // default

function ItineraryPageMap(
{
Expand Down

0 comments on commit d82b56b

Please sign in to comment.