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

DT-6476 Store and retrieve itinerary for Navigator from localStorage #5150

Merged
merged 21 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c17b576
feat: added functions to store itinerary in local storage
partisaani Nov 5, 2024
c28ff93
feat: store navigator itinerary in localStorage
partisaani Nov 5, 2024
2521585
chore: optimize and organize imports
partisaani Nov 5, 2024
09c5753
chore: ES6 syntax
partisaani Nov 5, 2024
0d8755f
chore: remove seemingly obsolete props
partisaani Nov 5, 2024
846222c
chore: update fetch-mock
partisaani Nov 5, 2024
e0a2453
feat: refactor Itineraries related tests into a directory
partisaani Nov 5, 2024
a1d6525
fix: removed old completely commented test file
partisaani Nov 5, 2024
f833898
fix: bump allowed variance for retryFetch test
partisaani Nov 5, 2024
9988d47
Revert "chore: ES6 syntax"
partisaani Nov 5, 2024
0809d1e
fix: itinerary legs as prop
partisaani Nov 6, 2024
869139b
fix: removed moment
partisaani Nov 6, 2024
4f80b61
feat: mount Navicontainer with custom hook
partisaani Nov 6, 2024
e6c9440
Merge commit 'd9dc785715e1cb1516afe452393f2eaac40007f7' into DT-6476
partisaani Nov 6, 2024
5c0934c
fix: added missing dependency array members
partisaani Nov 6, 2024
47d5b52
feat: toggled prefer-default-export rule off
partisaani Nov 7, 2024
7d1f8f4
fix: fixed bug in navigation mode setup
partisaani Nov 7, 2024
7045e0c
fix: fixed regression bug in map tracking
partisaani Nov 7, 2024
befc947
feat: added eslint plugin for react-hooks (tentative)
partisaani Nov 7, 2024
3692f62
Revert "feat: added eslint plugin for react-hooks (tentative)"
partisaani Nov 7, 2024
c73e278
Merge branch 'origin/v3' into DT-6476
partisaani Nov 8, 2024
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'import/no-extraneous-dependencies': 'off',
'import/no-named-default': 'off',
'import/extensions': 'off',
'import/prefer-default-export': 'off',
// react
'react/button-has-type': 'warn',
'react/destructuring-assignment': 'off',
Expand Down
1 change: 0 additions & 1 deletion app/action/FutureRoutesActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/prefer-default-export
export function saveFutureRoute(actionContext, futureRoute) {
actionContext.dispatch('saveFutureRoute', futureRoute);
}
1 change: 0 additions & 1 deletion app/action/SearchActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable import/prefer-default-export
export function saveSearch(actionContext, endpoint) {
actionContext.dispatch('SaveSearch', endpoint);
}
Expand Down
1 change: 0 additions & 1 deletion app/action/SearchSettingsActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/prefer-default-export
export function saveRoutingSettings(actionContext, settings) {
actionContext.dispatch('saveRoutingSettings', settings);
}
2 changes: 0 additions & 2 deletions app/action/userPreferencesActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/prefer-default-export */

export function setLanguage(actionContext, language) {
actionContext.dispatch('SetLanguage', language);
}
184 changes: 103 additions & 81 deletions app/component/itinerary/ItineraryPage.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,81 @@
/* eslint-disable react/no-array-index-key */
/* eslint-disable no-nested-ternary */
import PropTypes from 'prop-types';
import React, { useEffect, useState, useRef, cloneElement } from 'react';
import { fetchQuery } from 'react-relay';
import { FormattedMessage, intlShape } from 'react-intl';
import { matchShape, routerShape } from 'found';
import isEqual from 'lodash/isEqual';
import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';
import polyline from 'polyline-encoded';
import PropTypes from 'prop-types';
import React, { cloneElement, useEffect, useRef, useState } from 'react';
import { FormattedMessage, intlShape } from 'react-intl';
import { fetchQuery } from 'react-relay';
import { saveFutureRoute } from '../../action/FutureRoutesActions';
import { saveSearch } from '../../action/SearchActions';
import { TransportMode } from '../../constants';
import { mapLayerShape } from '../../store/MapLayerStore';
import {
clearLatestNavigatorItinerary,
getDialogState,
getLatestNavigatorItinerary,
setDialogState,
setLatestNavigatorItinerary,
} from '../../store/localStorage';
import { addAnalyticsEvent } from '../../util/analyticsUtils';
import { getWeatherData } from '../../util/apiUtils';
import { isIOS } from '../../util/browser';
import { boundWithMinimumArea } from '../../util/geo-utils';
import {
getIntermediatePlaces,
otpToLocation,
parseLatLon,
} from '../../util/otpStrings';
import { getItineraryPagePath, streetHash } from '../../util/path';
import {
PLANTYPE,
getPlanParams,
getSettings,
planQueryNeeded,
} from '../../util/planParamUtil';
import {
relayShape,
configShape,
mapLayerOptionsShape,
relayShape,
} from '../../util/shapes';
import { epochToTime } from '../../util/timeUtils';
import { getAllNetworksOfType } from '../../util/vehicleRentalUtils';
import DesktopView from '../DesktopView';
import Loading from '../Loading';
import MobileView from '../MobileView';
import ItineraryPageMap from '../map/ItineraryPageMap';
import ItineraryListContainer from './ItineraryListContainer';
import AlternativeItineraryBar from './AlternativeItineraryBar';
import CustomizeSearch from './CustomizeSearch';
import { spinnerPosition } from './ItineraryList';
import ItineraryListContainer from './ItineraryListContainer';
import ItineraryPageControls from './ItineraryPageControls';
import ItineraryTabs from './ItineraryTabs';
import { getWeatherData } from '../../util/apiUtils';
import Loading from '../Loading';
import { getItineraryPagePath, streetHash } from '../../util/path';
import { boundWithMinimumArea } from '../../util/geo-utils';
import planConnection from './PlanConnection';
import {
getSelectedItineraryIndex,
reportError,
addFeedbackly,
getTopics,
getBounds,
isEqualItineraries,
settingsLimitRouting,
setCurrentTimeToURL,
updateClient,
stopClient,
getRentalStationsToHideOnMap,
addBikeStationMapForRentalVehicleItineraries,
addFeedbackly,
checkDayNight,
filterItinerariesByFeedId,
filterWalk,
getBounds,
getRentalStationsToHideOnMap,
getSelectedItineraryIndex,
getTopics,
isEqualItineraries,
mergeBikeTransitPlans,
mergeScooterTransitPlan,
quitIteration,
reportError,
scooterEdges,
setCurrentTimeToURL,
settingsLimitRouting,
stopClient,
updateClient,
} from './ItineraryPageUtils';
import { isIOS } from '../../util/browser';
import { addAnalyticsEvent } from '../../util/analyticsUtils';
import {
parseLatLon,
otpToLocation,
getIntermediatePlaces,
} from '../../util/otpStrings';
import AlternativeItineraryBar from './AlternativeItineraryBar';
import {
PLANTYPE,
getSettings,
getPlanParams,
planQueryNeeded,
} from '../../util/planParamUtil';
import { epochToTime } from '../../util/timeUtils';
import { saveFutureRoute } from '../../action/FutureRoutesActions';
import { saveSearch } from '../../action/SearchActions';
import CustomizeSearch from './CustomizeSearch';
import { getAllNetworksOfType } from '../../util/vehicleRentalUtils';
import { TransportMode } from '../../constants';
import { mapLayerShape } from '../../store/MapLayerStore';
import ItineraryTabs from './ItineraryTabs';
import NaviContainer from './NaviContainer';
import NavigatorIntroModal from './NavigatorIntro/NavigatorIntroModal';
import { getDialogState, setDialogState } from '../../store/localStorage';
import planConnection from './PlanConnection';

const MAX_QUERY_COUNT = 4; // number of attempts to collect enough itineraries

Expand Down Expand Up @@ -607,15 +613,50 @@ export default function ItineraryPage(props, context) {
}
}

const setNavigation = enable => {
const getCombinedPlanEdges = () => {
return [
...(state.earlierEdges || []),
...(mapHashToPlan()?.edges || []),
...(state.laterEdges || []),
];
};

const getItinerarySelection = () => {
const hasNoTransitItineraries = filterWalk(state.plan?.edges).length === 0;
const plan = mapHashToPlan();
let combinedEdges;
// Remove old itineraries if new query cannot find a route
if (state.error) {
combinedEdges = [];
} else if (streetHashes.includes(hash)) {
combinedEdges = plan?.edges || [];
} else {
combinedEdges = getCombinedPlanEdges();
if (!hasNoTransitItineraries) {
// don't show plain walking in transit itinerary list
combinedEdges = filterWalk(combinedEdges);
}
}
const selectedIndex = getSelectedItineraryIndex(location, combinedEdges);

return { plan, combinedEdges, selectedIndex, hasNoTransitItineraries };
};

const setNavigation = isEnabled => {
if (mobileRef.current) {
mobileRef.current.setBottomSheet(enable ? 'bottom' : 'middle');
mobileRef.current.setBottomSheet(isEnabled ? 'bottom' : 'middle');
}
if (!enable) {
if (!isEnabled) {
setMapState({ center: undefined, zoom: undefined, bounds: undefined });
navigateMap();
clearLatestNavigatorItinerary();
} else {
const { combinedEdges, selectedIndex } = getItinerarySelection();
if (combinedEdges[selectedIndex]?.node) {
setLatestNavigatorItinerary(combinedEdges[selectedIndex]?.node);
}
}
setNaviMode(enable);
setNaviMode(isEnabled);
};

// save url-defined location to old searches
Expand Down Expand Up @@ -704,39 +745,17 @@ export default function ItineraryPage(props, context) {
);
}

function getCombinedPlanEdges() {
return [
...(state.earlierEdges || []),
...(mapHashToPlan()?.edges || []),
...(state.laterEdges || []),
];
}

function getItinerarySelection() {
const hasNoTransitItineraries = filterWalk(state.plan?.edges).length === 0;
const plan = mapHashToPlan();
let combinedEdges;
// Remove old itineraries if new query cannot find a route
if (state.error) {
combinedEdges = [];
} else if (streetHashes.includes(hash)) {
combinedEdges = plan?.edges || [];
} else {
combinedEdges = getCombinedPlanEdges();
if (!hasNoTransitItineraries) {
// don't show plain walking in transit itinerary list
combinedEdges = filterWalk(combinedEdges);
}
}
const selectedIndex = getSelectedItineraryIndex(location, combinedEdges);

return { plan, combinedEdges, selectedIndex, hasNoTransitItineraries };
}

useEffect(() => {
setCurrentTimeToURL(config, match);
updateLocalStorage(true);
addFeedbackly(context);

const storedItinerary = getLatestNavigatorItinerary();

setNavigation(
storedItinerary?.end && Date.parse(storedItinerary.end) > Date.now(),
);

return () => {
if (showVehicles()) {
stopClient(context);
Expand Down Expand Up @@ -1110,6 +1129,7 @@ export default function ItineraryPage(props, context) {
// in mobile, settings drawer hides other content
const panelHidden = !desktop && settingsDrawer !== null;
let content; // bottom content of itinerary panel

if (panelHidden) {
content = null;
} else if (loading) {
Expand All @@ -1120,6 +1140,9 @@ export default function ItineraryPage(props, context) {
);
} else if (detailView) {
if (naviMode) {
const naviModeItinerary =
getLatestNavigatorItinerary() || combinedEdges[selectedIndex]?.node;

content = (
<>
{!isNavigatorIntroDismissed && (
Expand All @@ -1130,10 +1153,9 @@ export default function ItineraryPage(props, context) {
/>
)}
<NaviContainer
itinerary={combinedEdges[selectedIndex]?.node}
itinerary={naviModeItinerary}
partisaani marked this conversation as resolved.
Show resolved Hide resolved
focusToLeg={focusToLeg}
relayEnvironment={props.relayEnvironment}
combinedEdges={combinedEdges}
setNavigation={setNavigation}
mapRef={mwtRef.current}
/>
Expand Down
Loading
Loading