Skip to content
Merged
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
5 changes: 0 additions & 5 deletions app/action/MapLayerActions.js

This file was deleted.

2 changes: 0 additions & 2 deletions app/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Fluxible from 'fluxible';
import routes from '../routes/routes';
import PositionStore from '../store/PositionStore';
import RealTimeInformationStore from '../store/RealTimeInformationStore';
import MapLayerStore from '../store/MapLayerStore';

export default config => {
const app = new Fluxible({
Expand All @@ -12,7 +11,6 @@ export default config => {

app.registerStore(PositionStore);
app.registerStore(RealTimeInformationStore);
app.registerStore(MapLayerStore);

app.plug({
name: 'extra-context-plugin',
Expand Down
2 changes: 2 additions & 0 deletions app/client/client.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import favouriteStore from '../data/FavouriteData';
import searchContext from '../data/SearchContext';
import { ConfigProvider } from './ConfigContext';
import { FavouriteProvider } from '../hooks/FavouriteContext';
import { MapLayerProvider } from '../hooks/MapLayerContext';
import { MessageProvider } from '../hooks/MessageContext';
import { TimeProvider } from '../hooks/TimeContext';
import { ItineraryLocationProvider } from '../hooks/ItineraryLocationContext';
Expand Down Expand Up @@ -69,6 +70,7 @@ const AppProviders = props => {
[RelayEnvironmentProvider, { environment: props.environment }],
[MessageProvider],
[FavouriteProvider],
[MapLayerProvider],
[TimeProvider],
[ItineraryLocationProvider],
];
Expand Down
61 changes: 41 additions & 20 deletions app/component/itinerary/ItineraryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import PropTypes from 'prop-types';
import React, {
cloneElement,
useEffect,
useContext,
useMemo,
useRef,
useState,
} from 'react';
import { FormattedMessage } from 'react-intl';
import { fetchQuery } from 'react-relay';
import { fetchQuery, ReactRelayContext } from 'react-relay';
import { useRouter } from 'found';
import { useBreakpoint } from '../../../utils/client/withBreakpoint';
import { saveFutureRoute } from '../../../utils/client/storeUtils';
import { startLocationWatch } from '../../action/PositionActions';
import { saveSearch } from '../../data/SearchHistory';
import { TransportMode } from '../../../utils/shared/constants';
import { mapLayerShape } from '../../store/MapLayerStore';
import {
clearLatestNavigatorItinerary,
getDialogState,
Expand All @@ -44,14 +45,16 @@ import {
planQueryNeeded,
PLANTYPE,
} from '../../../utils/client/planParamUtil';
import { mapLayerOptionsShape, relayShape } from '../../../utils/client/shapes';
import { epochToTime } from '../../../utils/client/timeUtils';
import { getMapLayerOptions } from '../../../utils/client/mapLayerUtils';
import { getAllNetworksOfType } from '../../../utils/shared/vehicleRentalUtils';
import { isPersonalizationEnabled } from '../../../utils/client/modeUtils';
import {
useFavouriteActions,
useFavourites,
usePersonalizationPreferences,
} from '../../hooks/FavouriteContext';
import { getFavouriteRouteGtfsIds } from '../../data/FavouriteData';
import DesktopView from '../DesktopView';
import Loading from '../Loading';
import MobileView from '../MobileView';
Expand Down Expand Up @@ -92,14 +95,18 @@ import {
applyFeedback,
} from './ItineraryPageUtils';
import ItineraryTabs from './ItineraryTabs';
import { useItineraryContext } from './context/ItineraryContext';
import {
ItineraryContextProvider,
useItineraryContext,
} from './context/ItineraryContext';
import { REDUCER_ACTION_TYPES } from './context/useItineraryReducer';
import NaviContainer from './navigator/NaviContainer';
import NaviGeolocationInfoModal from './navigator/navigatorgeolocation/NaviGeolocationInfoModal';
import NavigatorIntroModal from './navigator/navigatorintro/NavigatorIntroModal';
import { planConnection } from './queries/PlanConnection';
import { isCallAgencyLeg, hasTaxiLegs } from '../../../utils/client/legUtils';
import { hasTaxiLegs, isCallAgencyLeg } from '../../../utils/client/legUtils';
import { useConfigContext } from '../../client/ConfigContext';
import { useMapLayers } from '../../hooks/MapLayerContext';

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

Expand Down Expand Up @@ -147,8 +154,15 @@ const unset = { plan: {}, loading: LOADSTATE.UNSET };

const noFocus = { center: undefined, zoom: undefined, bounds: undefined };

export default function ItineraryPage(props, context) {
const DEFAULT_LAYER_OPTIONS = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles'],
});

function ItineraryPageContent(props, context) {
const { match: routerMatch, router } = useRouter();
const { environment: relayEnvironment } = useContext(ReactRelayContext);
const breakpoint = useBreakpoint();
// found's useRouter() exposes the globally current match. While navigating
// away to an unrelated, paramless route (e.g. the embedded search generator
// from MainMenu), the router context can update to the new route's match
Expand All @@ -163,6 +177,11 @@ export default function ItineraryPage(props, context) {
}
const match = lastValidMatchRef.current;
const config = useConfigContext();
const { mapLayers } = useMapLayers({
notThese: ['stop', 'citybike', 'vehicles', 'scooter'],
});
const favouriteRoutes = getFavouriteRouteGtfsIds(useFavourites());
const defaultMapLayerOptions = DEFAULT_LAYER_OPTIONS;
const headerRef = useRef(null);
const mwtRef = useRef();
const mobileRef = useRef();
Expand Down Expand Up @@ -236,7 +255,6 @@ export default function ItineraryPage(props, context) {
const itineraryContext = useItineraryContext();

const { executeAction } = context;
const { breakpoint } = props;
const { params, location } = match;
const { hash, secondHash } = params;
const { query } = location;
Expand Down Expand Up @@ -384,7 +402,7 @@ export default function ItineraryPage(props, context) {
for (let i = 0; i < trials; i++) {
// eslint-disable-next-line no-await-in-loop
const result = await fetchQuery(
props.relayEnvironment,
relayEnvironment,
planConnection,
planParams,
{
Expand Down Expand Up @@ -1242,7 +1260,7 @@ export default function ItineraryPage(props, context) {
recommendedItinerary.current = rateItineraries(
plan.edges,
weights.current,
props.favouriteRoutes,
favouriteRoutes,
);
}
setCombinedMainState({ plan, loading: LOADSTATE.DONE });
Expand Down Expand Up @@ -1462,16 +1480,16 @@ export default function ItineraryPage(props, context) {

const mapLayerOptions = itineraryContainsDepartureFromVehicleRentalStation
? addBikeStationMapForRentalVehicleItineraries(planEdges)
: props.mapLayerOptions;
: defaultMapLayerOptions;

const flexLeg = planEdges?.[activeIndex]?.node.legs.find(leg =>
isCallAgencyLeg(leg),
);
const updatedMapLayers = { ...props.mapLayers };
const flexRouteGtfsId = flexLeg?.route?.gtfsId.split(':')[0];
const isFlexBus = config.flex.internal.agencies.find(
agency => agency.split(':')[0] === flexRouteGtfsId,
);
const updatedMapLayers = { ...mapLayers };
if (isFlexBus && flexRouteGtfsId) {
updatedMapLayers.areaStop = { routeGtfsId: flexRouteGtfsId };
}
Expand Down Expand Up @@ -1649,7 +1667,7 @@ export default function ItineraryPage(props, context) {
<NaviContainer
focusToLeg={focusToLeg}
focusToPoint={focusToPoint}
relayEnvironment={props.relayEnvironment}
relayEnvironment={relayEnvironment}
setNavigation={setNavigation}
mapRef={mwtRef.current}
mapLayerRef={mapLayerRef}
Expand Down Expand Up @@ -1689,7 +1707,7 @@ export default function ItineraryPage(props, context) {
bikePublicItineraryCount={bikePublicPlan.bikePublicItineraryCount}
carPublicItineraryCount={carPublicPlan.carPublicItineraryCount}
openSettings={showSettingsPanel}
relayEnvironment={props.relayEnvironment}
relayEnvironment={relayEnvironment}
startNavigation={navigateHook}
/>
);
Expand Down Expand Up @@ -1823,17 +1841,20 @@ export default function ItineraryPage(props, context) {
);
}

ItineraryPage.contextTypes = {
ItineraryPageContent.contextTypes = {
executeAction: PropTypes.func.isRequired,
getStore: PropTypes.func,
};

ItineraryPage.propTypes = {
ItineraryPageContent.propTypes = {
content: PropTypes.node,
map: PropTypes.shape({ type: PropTypes.func.isRequired }),
breakpoint: PropTypes.string.isRequired,
relayEnvironment: relayShape.isRequired,
mapLayers: mapLayerShape.isRequired,
mapLayerOptions: mapLayerOptionsShape.isRequired,
favouriteRoutes: PropTypes.arrayOf(PropTypes.string).isRequired,
};

export default function ItineraryPage(props) {
return (
<ItineraryContextProvider>
<ItineraryPageContent {...props} />
</ItineraryContextProvider>
);
}
46 changes: 0 additions & 46 deletions app/component/itinerary/ItineraryPageContainer.jsx

This file was deleted.

21 changes: 4 additions & 17 deletions app/component/map/IndexPageMap.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react';
import { connectToStores } from 'fluxible-addons-react';
import { useMatch } from 'found';
import MapWithTracking from './MapWithTracking';
import { sameLocations } from '../../../utils/shared/path';
import { useConfigContext } from '../../client/ConfigContext';
// eslint-disable-next-line import/no-named-as-default
import { mapLayerShape } from '../../store/MapLayerStore';
import { useMapLayers } from '../../hooks/MapLayerContext';
import CookieSettingsButton from '../CookieSettingsButton';
import LocationMarker from './LocationMarker';
import {
Expand All @@ -17,8 +15,9 @@ import {
let focus = {};
const mwtProps = {};

function IndexPageMap({ mapLayers }) {
function IndexPageMap() {
const config = useConfigContext();
const { mapLayers } = useMapLayers();
const match = useMatch();
const origin = useOrigin();
const destination = useDestination();
Expand Down Expand Up @@ -96,16 +95,4 @@ function IndexPageMap({ mapLayers }) {
);
}

IndexPageMap.propTypes = {
mapLayers: mapLayerShape.isRequired,
};

const IndexPageMapWithStores = connectToStores(
IndexPageMap,
['MapLayerStore'],
({ getStore }) => ({
mapLayers: getStore('MapLayerStore').getMapLayers(),
}),
);

export { IndexPageMapWithStores as default, IndexPageMap as Component };
export default IndexPageMap;
2 changes: 1 addition & 1 deletion app/component/map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { boundWithMinimumArea } from '../../../utils/shared/geo-utils';
import events from '../../../utils/client/events';
import { getLayerBaseUrl } from '../../../utils/client/mapLayerUtils';
import GeoJSON from './GeoJSON';
import { mapLayerShape } from '../../store/MapLayerStore';
import { useConfigContext } from '../../client/ConfigContext';
import { mapLayerShape } from '../../../utils/client/shapes';

const zoomOutText = `<svg class="icon"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon_minus"/></svg>`;
const zoomInText = `<svg class="icon"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon_plus"/></svg>`;
Expand Down
Loading
Loading