Skip to content

Commit

Permalink
Merge branch 'v3' into DT-6476_patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
partisaani committed Nov 12, 2024
2 parents 41a6d44 + daac13f commit 5f74888
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 232 deletions.
10 changes: 3 additions & 7 deletions app/component/StopsNearYouFavoritesMapContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import connectToStores from 'fluxible-addons-react/connectToStores';
import { graphql, createFragmentContainer } from 'react-relay';
import distance from '@digitransit-search-util/digitransit-search-util-distance';
import StopsNearYouMap from './map/StopsNearYouMap';
import TimeStore from '../store/TimeStore';
import PreferencesStore from '../store/PreferencesStore';
import FavouriteStore from '../store/FavouriteStore';
import {
Expand Down Expand Up @@ -84,16 +83,13 @@ StopsNearYouFavoritesMapContainer.defaultProps = {

const StopsNearYouMapWithStores = connectToStores(
StopsNearYouFavoritesMapContainer,
[TimeStore, PreferencesStore, FavouriteStore],
[PreferencesStore, FavouriteStore],
({ getStore }) => {
const currentTime = getStore(TimeStore).getCurrentTime();
const language = getStore(PreferencesStore).getLanguage();
return {
language,
currentTime,
};
return { language };
},
);

const containerComponent = createFragmentContainer(StopsNearYouMapWithStores, {
stops: graphql`
fragment StopsNearYouFavoritesMapContainer_stops on Stop
Expand Down
5 changes: 1 addition & 4 deletions app/component/StopsNearYouMapContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import connectToStores from 'fluxible-addons-react/connectToStores';
import { graphql, createPaginationContainer } from 'react-relay';
import StopsNearYouMap from './map/StopsNearYouMap';

import TimeStore from '../store/TimeStore';
import FavouriteStore from '../store/FavouriteStore';
import PreferencesStore from '../store/PreferencesStore';

const StopsNearYouMapWithStores = connectToStores(
StopsNearYouMap,
[TimeStore, PreferencesStore, FavouriteStore],
[PreferencesStore, FavouriteStore],
({ getStore }, { match }) => {
const currentTime = getStore(TimeStore).getCurrentTime();
const language = getStore(PreferencesStore).getLanguage();
const favouriteIds =
match.params.mode === 'CITYBIKE'
Expand All @@ -26,7 +24,6 @@ const StopsNearYouMapWithStores = connectToStores(
);
return {
language,
currentTime,
favouriteIds,
};
},
Expand Down
7 changes: 5 additions & 2 deletions app/component/itinerary/MobileTicketPurchaseInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default function MobileTicketPurchaseInformation(
!fare.isUnknown,
config.availableTickets,
);
const price = `${fare.price.toFixed(2)} €`.replace('.', ',');
const price =
config.showTicketPrice && fare.price > 0
? `${fare.price.toFixed(2)} €`.replace('.', ',')
: '';

const faresInfo = () => {
const header = `${intl.formatMessage({
Expand Down Expand Up @@ -64,7 +67,7 @@ export default function MobileTicketPurchaseInformation(
addAnalyticsEvent({ event: 'journey_planner_open_app' })
}
>
<FormattedMessage id="open-app" />
<FormattedMessage id={config.ticketButtonTextId} />
</ExternalLink>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
.external-link-container {
border: 0;
line-height: 25px;
padding: 0 10px;

a.external-link {
font-size: 16px;
Expand Down
3 changes: 2 additions & 1 deletion app/component/map/ItineraryLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ class ItineraryLine extends React.Component {
static propTypes = {
legs: PropTypes.arrayOf(legShape).isRequired,
passive: PropTypes.bool,
hash: PropTypes.number.isRequired,
hash: PropTypes.number,
showTransferLabels: PropTypes.bool,
showIntermediateStops: PropTypes.bool,
showDurationBubble: PropTypes.bool,
streetMode: PropTypes.string,
};

static defaultProps = {
hash: 0,
passive: false,
streetMode: undefined,
showTransferLabels: false,
Expand Down
107 changes: 36 additions & 71 deletions app/component/map/StopPageMap.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import PropTypes from 'prop-types';
import React, { useEffect, useContext, useState } from 'react';
import { matchShape, routerShape } from 'found';
import moment from 'moment';
import { connectToStores } from 'fluxible-addons-react';
import distance from '@digitransit-search-util/digitransit-search-util-distance';
import { graphql, fetchQuery } from 'react-relay';
import { fetchQuery } from 'react-relay';
import ReactRelayContext from 'react-relay/lib/ReactRelayContext';
import {
configShape,
locationShape,
mapLayerOptionsShape,
} from '../../util/shapes';
import { getSettings } from '../../util/planParamUtil';
import TimeStore from '../../store/TimeStore';
import PositionStore from '../../store/PositionStore';
import MapLayerStore, { mapLayerShape } from '../../store/MapLayerStore';
import MapWithTracking from './MapWithTracking';
Expand All @@ -21,13 +19,13 @@ import SelectedStopPopupContent from '../SelectedStopPopupContent';
import withBreakpoint from '../../util/withBreakpoint';
import VehicleMarkerContainer from './VehicleMarkerContainer';
import BackButton from '../BackButton';
import { locationToUri } from '../../util/otpStrings';
import ItineraryLine from './ItineraryLine';
import Loading from '../Loading';
import { getMapLayerOptions } from '../../util/mapLayerUtils';
import MapRoutingButton from '../MapRoutingButton';
import CookieSettingsButton from '../CookieSettingsButton';
import { PREFIX_CARPARK, PREFIX_BIKEPARK } from '../../util/path';
import { walkQuery } from './WalkQuery';

const getModeFromProps = props => {
if (props.citybike) {
Expand All @@ -49,15 +47,7 @@ const getModeFromProps = props => {
};

function StopPageMap(
{
stop,
breakpoint,
currentTime,
locationState,
mapLayers,
mapLayerOptions,
stopName,
},
{ stop, breakpoint, locationState, mapLayers, mapLayerOptions, stopName },
{ config, match },
) {
if (!stop) {
Expand All @@ -66,67 +56,48 @@ function StopPageMap(

const maxShowRouteDistance = breakpoint === 'large' ? 900 : 470;
const { environment } = useContext(ReactRelayContext);
const [plan, setPlan] = useState({ plan: {}, isFetching: false });
const [walk, setWalk] = useState(null);

useEffect(() => {
let isMounted = true;
const fetchPlan = async targetStop => {
const fetchWalk = async targetStop => {
if (locationState.hasLocation && locationState.address) {
if (distance(locationState, stop) < maxShowRouteDistance) {
const toPlace = {
address: targetStop.name ? targetStop.name : 'stop',
lon: targetStop.lon,
lat: targetStop.lat,
};
const settings = getSettings(config);
const variables = {
fromPlace: locationToUri(locationState),
toPlace: locationToUri(toPlace),
date: moment(currentTime * 1000).format('YYYY-MM-DD'),
time: moment(currentTime * 1000).format('HH:mm:ss'),
origin: {
location: {
coordinate: {
latitude: locationState.lat,
longitude: locationState.lon,
},
},
},
destination: {
location: {
coordinate: {
latitude: targetStop.lat,
longitude: targetStop.lon,
},
},
},
walkSpeed: settings.walkSpeed,
wheelchair: !!settings.accessibilityOption,
};
const query = graphql`
query StopPageMapQuery(
$fromPlace: String!
$toPlace: String!
$date: String!
$time: String!
$walkSpeed: Float
$wheelchair: Boolean
) {
plan: plan(
fromPlace: $fromPlace
toPlace: $toPlace
date: $date
time: $time
transportModes: [{ mode: WALK }]
walkSpeed: $walkSpeed
wheelchair: $wheelchair
) {
itineraries {
legs {
mode
...ItineraryLine_legs
}
}
}
}
`;
fetchQuery(environment, query, variables)
fetchQuery(environment, walkQuery, variables)
.toPromise()
.then(({ plan: result }) => {
.then(result => {
if (isMounted) {
setPlan({ plan: result, isFetching: false });
setWalk(
result.plan.edges.length ? result.plan.edges?.[0].node : null,
);
}
});
}
}
};
if (stop && locationState.hasLocation) {
setPlan({ plan: plan.plan, isFetching: true });
fetchPlan(stop);
fetchWalk(stop);
}
return () => {
isMounted = false;
Expand Down Expand Up @@ -161,18 +132,15 @@ function StopPageMap(
);
}

if (plan.plan.itineraries) {
if (walk) {
leafletObjs.push(
...plan.plan.itineraries.map((itinerary, i) => (
<ItineraryLine
key="itinerary"
hash={i}
legs={itinerary.legs}
passive={false}
showIntermediateStops={false}
streetMode="walk"
/>
)),
<ItineraryLine
key="walk"
legs={walk.legs}
passive={false}
showIntermediateStops={false}
streetMode="walk"
/>,
);
}
const id = match.params.stopId || match.params.terminalId || match.params.id;
Expand Down Expand Up @@ -229,7 +197,6 @@ StopPageMap.propTypes = {
}),
breakpoint: PropTypes.string.isRequired,
locationState: locationShape.isRequired,
currentTime: PropTypes.number.isRequired,
mapLayers: mapLayerShape.isRequired,
mapLayerOptions: mapLayerOptionsShape.isRequired,
parkType: PropTypes.string,
Expand All @@ -246,9 +213,8 @@ const componentWithBreakpoint = withBreakpoint(StopPageMap);

const StopPageMapWithStores = connectToStores(
componentWithBreakpoint,
[TimeStore, PositionStore, MapLayerStore],
[PositionStore, MapLayerStore],
({ config, getStore }, props) => {
const currentTime = getStore(TimeStore).getCurrentTime();
const locationState = getStore(PositionStore).getLocationState();
const ml = config.showVehiclesOnStopPage ? { notThese: ['vehicles'] } : {};
if (props.citybike) {
Expand All @@ -266,7 +232,6 @@ const StopPageMapWithStores = connectToStores(
});
return {
locationState,
currentTime,
mapLayers,
mapLayerOptions,
};
Expand Down
Loading

0 comments on commit 5f74888

Please sign in to comment.