-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5134 from HSLdevcom/DT-6461
DT-6461: Use geolocation to improve accuracy of navigation instructions
- Loading branch information
Showing
10 changed files
with
351 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,47 @@ | ||
import React from 'react'; | ||
import { FormattedMessage, intlShape } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
import { legShape } from '../../util/shapes'; | ||
import Icon from '../Icon'; | ||
import { legDestination, isRental } from '../../util/legUtils'; | ||
import NaviDestination from './NaviDestination'; | ||
import { isRental } from '../../util/legUtils'; | ||
import NaviLegContent from './NaviLegContent'; | ||
|
||
const iconMap = { | ||
BICYCLE: 'icon-icon_cyclist', | ||
CAR: 'icon-icon_car-withoutBox', | ||
SCOOTER: 'icon-icon_scooter_rider', | ||
WALK: 'icon-icon_walk', | ||
WAIT: 'icon-icon_navigation_wait', | ||
}; | ||
|
||
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ | ||
export default function NaviLeg({ leg, nextLeg }, { intl }) { | ||
const iconName = iconMap[leg.mode]; | ||
let goTo = `navileg-${leg.mode.toLowerCase()}`; | ||
export default function NaviLeg({ leg, nextLeg, legType }) { | ||
const iconName = legType === 'wait' ? iconMap.WAIT : iconMap[leg.mode]; | ||
let instructions = `navileg-${leg.mode.toLowerCase()}`; | ||
|
||
if (isRental(leg, nextLeg)) { | ||
if (leg.mode === 'WALK' && nextLeg?.mode === 'SCOOTER') { | ||
goTo = `navileg-rent-scooter`; | ||
instructions = `navileg-rent-scooter`; | ||
} else { | ||
goTo = `navileg-rent-cycle`; | ||
instructions = `navileg-rent-cycle`; | ||
} | ||
} | ||
return ( | ||
<div> | ||
<div className="navileg-goto"> | ||
<Icon img={iconName} color="black" className="navileg-mode" /> | ||
<div className="navileg-divider" /> | ||
<div className="navileg-destination"> | ||
<div className="destination-header"> | ||
<FormattedMessage id={goTo} defaultMessage="Go to" /> | ||
| ||
{legDestination(intl, leg, null, nextLeg)} | ||
</div> | ||
<NaviDestination leg={leg} /> | ||
</div> | ||
<div className="navileg-goto"> | ||
<Icon img={iconName} color="black" className="navileg-mode" /> | ||
<div className="navileg-divider" /> | ||
<div className="navileg-destination"> | ||
<NaviLegContent | ||
leg={leg} | ||
nextLeg={nextLeg} | ||
instructions={instructions} | ||
legType={legType} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
NaviLeg.propTypes = { | ||
leg: legShape.isRequired, | ||
nextLeg: legShape, | ||
}; | ||
|
||
NaviLeg.defaultProps = { | ||
nextLeg: null, | ||
}; | ||
|
||
NaviLeg.contextTypes = { | ||
intl: intlShape.isRequired, | ||
nextLeg: legShape.isRequired, | ||
legType: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import { FormattedMessage, intlShape } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
import { legShape } from '../../util/shapes'; | ||
import { legDestination } from '../../util/legUtils'; | ||
import NaviDestination from './NaviDestination'; | ||
import RouteNumber from '../RouteNumber'; | ||
|
||
export default function NaviLegContent( | ||
{ leg, nextLeg, instructions, legType }, | ||
{ intl }, | ||
) { | ||
if (legType === 'move') { | ||
return ( | ||
<> | ||
<div className="destination-header"> | ||
<FormattedMessage id={instructions} defaultMessage="Go to" /> | ||
| ||
{legDestination(intl, leg, null, nextLeg)} | ||
</div> | ||
<NaviDestination leg={leg} /> | ||
</> | ||
); | ||
} | ||
|
||
if (legType === 'wait') { | ||
const { mode, headsign, route } = nextLeg; | ||
|
||
const color = route.color ? route.color : 'currentColor'; | ||
const localizedMode = intl.formatMessage({ | ||
id: `${mode.toLowerCase()}`, | ||
defaultMessage: `${mode}`, | ||
}); | ||
return ( | ||
<> | ||
<div className="destination-header"> | ||
<FormattedMessage | ||
id="navigation-wait-mode" | ||
values={{ mode: localizedMode }} | ||
defaultMessage="Wait for" | ||
/> | ||
</div> | ||
<div className="wait-leg"> | ||
<RouteNumber | ||
mode={mode.toLowerCase()} | ||
text={route?.shortName} | ||
withBar | ||
isTransitLeg | ||
color={color} | ||
/> | ||
<div className="headsign">{headsign}</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
NaviLegContent.propTypes = { | ||
leg: legShape.isRequired, | ||
nextLeg: legShape.isRequired, | ||
instructions: PropTypes.string.isRequired, | ||
legType: PropTypes.string, | ||
}; | ||
|
||
NaviLegContent.defaultProps = { | ||
legType: 'move', | ||
}; | ||
NaviLegContent.contextTypes = { | ||
intl: intlShape.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.