Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Add hove instruction converter for default transport mode #1378

Merged
merged 2 commits into from
Jul 22, 2022
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
21 changes: 21 additions & 0 deletions src/libs/route_utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global _ */
/* eslint-disable no-irregular-whitespace */
import { normalizeToFeatureCollection } from './geojson';

Expand Down Expand Up @@ -84,3 +85,23 @@ export const originDestinationCoords = route => {

return { origin, destination };
};

export const walkingManeuver = maneuver => {
const stringifyModifier = {
'sharp left': _('Turn left', 'direction'),
left: _('Turn left', 'direction'),
'slight left': _('Keep left', 'direction'),
straight: _('Walk', 'direction'),
'slight right': _('Keep right', 'direction'),
right: _('Turn right', 'direction'),
'sharp right': _('Turn right', 'direction'),
uturn: _('Turn back', 'direction'),
};

const context = {
modifier: stringifyModifier[maneuver.modifier],
name: maneuver.detail.name,
};

return maneuver.detail.name ? _('{modifier} on {name}', 'direction', context) : context.modifier;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import RoadMapStep from '../../RoutesList/Route/RoadMap/RoadMapStep';
import DefaultRoadMapStep from '../../RoutesList/Route/RoadMap/Default/DefaultRoadMapStep';
import { fire } from 'src/libs/customEvents';
import classnames from 'classnames';
import { FloatingButton } from 'src/components/ui';
Expand Down Expand Up @@ -61,7 +61,7 @@ const MobileRoadMapPreview = ({ steps, onClose }) => {
active: index === currentStep,
})}
>
<RoadMapStep step={step} />
<DefaultRoadMapStep step={step} />
</div>
))}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/panel/direction/PublicTransportLine/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Color from 'color';
import cx from 'classnames';
import { components } from 'appTypes/idunn';
import { Text } from '@qwant/qwant-ponents';
import RoadMapIcon from '../RoutesList/Route/RoadMap/RoadMapIcon';
import DefaultRoadMapIcon from '../RoutesList/Route/RoadMap/Default/DefaultRoadMapIcon';
import { getTransportTypeIcon } from 'src/libs/route_utils';

export type PublicTransportLineProps = {
Expand Down Expand Up @@ -37,7 +37,7 @@ const PublicTransportLine: React.FunctionComponent<PublicTransportLineProps> = (
<>
<div className="oval" />
{mode && (
<RoadMapIcon
<DefaultRoadMapIcon
className="routePtLine__transport-icon"
iconClass={getTransportTypeIcon({ mode })}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

const LegLine = ({ mode, info }) => {
const DefaultLegLine = ({ mode, info }) => {
if (mode === 'WALK') {
return <div className="itinerary_roadmap_line itinerary_roadmap_line--walk" />;
}
Expand All @@ -12,4 +12,4 @@ const LegLine = ({ mode, info }) => {
);
};

export default LegLine;
export default DefaultLegLine;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import DefaultRoadMapPoint from '../DefaultRoadMapPoint';
import DefaultRoadMapStep from '../DefaultRoadMapStep';
import { fire } from 'src/libs/customEvents';
import { components } from 'appTypes/idunn';
import IdunnPoi from 'src/adapters/poi/idunn_poi';

export type DefaultRoadMapProps = {
routeSteps: components['schemas']['RouteStep'][];
destination: IdunnPoi;
origin: IdunnPoi;
};

const DefaultRoadMap: React.FunctionComponent<DefaultRoadMapProps> = ({
origin,
destination,
routeSteps,
}) => {
return (
<div className="itinerary_roadmap">
<DefaultRoadMapPoint point={origin} onClick={() => fire('fit_map', origin)} />
{routeSteps.map((step, index) => (
<DefaultRoadMapStep
key={index}
step={step}
onMouseOver={() => {
fire('highlight_step', index);
}}
onMouseOut={() => {
fire('unhighlight_step', index);
}}
onClick={() => {
fire('zoom_step', step);
}}
/>
))}
<DefaultRoadMapPoint point={destination} onClick={() => fire('fit_map', destination)} />
</div>
);
};

export default DefaultRoadMap;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import cx from 'classnames';

const RoadMapIcon = ({ className = '', iconClass }) => (
const DefaultRoadMapIcon = ({ className = '', iconClass }) => (
<div className={cx(className, 'roadmapIcon', `roadmapIcon--${iconClass}`)} />
);

export default RoadMapIcon;
export default DefaultRoadMapIcon;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classnames from 'classnames';
import { Flex } from '@qwant/qwant-ponents';
import { Divider } from 'src/components/ui';

const RoadMapItem = ({ children, icon, distance, className, line, alignTop, ...rest }) => (
const DefaultRoadMapItem = ({ children, icon, distance, className, line, alignTop, ...rest }) => (
<>
<div className={classnames('itinerary_roadmap_item', className)} {...rest}>
{line}
Expand All @@ -19,4 +19,4 @@ const RoadMapItem = ({ children, icon, distance, className, line, alignTop, ...r
</>
);

export default RoadMapItem;
export default DefaultRoadMapItem;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import RoadMapItem from '../RoadMapItem';
import DefaultRoadMapItem from '../DefaultRoadMapItem';
import { getInputValue } from 'src/libs/suggest';
import Address from 'src/components/ui/Address';
import PlaceIcon from 'src/components/PlaceIcon';

const RoadMapPoint = ({ point, ...rest }) => {
const DefaultRoadMapPoint = ({ point, ...rest }) => {
const { address, type } = point;

return (
<RoadMapItem icon={<PlaceIcon place={point} withBackground />} {...rest}>
<DefaultRoadMapItem icon={<PlaceIcon place={point} withBackground />} {...rest}>
<div className="u-text--smallTitle">{getInputValue(point)}</div>
{type !== 'geoloc' && (
<div className="u-text--subtitle">
Expand All @@ -20,8 +20,8 @@ const RoadMapPoint = ({ point, ...rest }) => {
/>
</div>
)}
</RoadMapItem>
</DefaultRoadMapItem>
);
};

export default RoadMapPoint;
export default DefaultRoadMapPoint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { formatDistance, getStepIcon } from 'src/libs/route_utils';
import DefaultRoadMapItem from '../DefaultRoadMapItem';
import DefaultRoadMapIcon from '../DefaultRoadMapIcon';
import { walkingManeuver } from 'src/libs/route_utils';

const DefaultRoadMapStep = ({ step, ...rest }) => (
<DefaultRoadMapItem
icon={<DefaultRoadMapIcon iconClass={getStepIcon(step)} />}
distance={step.distance ? formatDistance(step.distance) : null}
alignTop
{...rest}
>
{step.maneuver.instruction || walkingManeuver(step.maneuver)}
</DefaultRoadMapItem>
);

export default DefaultRoadMapStep;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react';
import PublicTransportRoadMapItem from '../PublicTransportRoadMapItem';
import RoadMapIcon from '../../RoadMapIcon';
import DefaultRoadMapIcon from '../../Default/DefaultRoadMapIcon';
import PublicTransportLine from '../../../../../PublicTransportLine';
import LegLine from '../../LegLine';
import DefaultLegLine from '../../Default/DefaultLegLine';
import cx from 'classnames';
import { getTransportTypeIcon, formatDuration } from 'src/libs/route_utils';
import { Chevron } from 'src/components/ui';
Expand All @@ -16,13 +16,13 @@ const PublicTransportLineLeg = ({ leg }) => {

return (
<PublicTransportRoadMapItem
icon={<RoadMapIcon iconClass={getTransportTypeIcon(leg)} />}
icon={<DefaultRoadMapIcon iconClass={getTransportTypeIcon(leg)} />}
className={cx(
'itinerary_roadmap_item--transportLine',
stops?.length === 0 && 'itinerary_roadmap_item--no-hover'
)}
type="TRANSPORT_LINE"
line={<LegLine info={info} mode={mode} />}
line={<DefaultLegLine info={info} mode={mode} />}
>
<div className="itinerary_roadmap_item_summary" onClick={() => setDetailsOpen(!detailsOpen)}>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
/* global _ */
/* globals _ */

import React, { useState } from 'react';
import { formatDistance, formatDuration } from 'src/libs/route_utils';
import PublicTransportRoadMapItem from '../PublicTransportRoadMapItem';
import RoadMapIcon from '../../RoadMapIcon';
import LegLine from '../../LegLine';
import RoadMapIcon from '../../Default/DefaultRoadMapIcon';
import DefaultLegLine from '../../Default/DefaultLegLine';
import cx from 'classnames';
import { Chevron } from 'src/components/ui';

const stringifyManeuver = maneuver => {
const stringifyModifier = {
'sharp left': _('Turn left', 'direction'),
left: _('Turn left', 'direction'),
'slight left': _('Keep left', 'direction'),
straight: _('Walk', 'direction'),
'slight right': _('Keep right', 'direction'),
right: _('Turn right', 'direction'),
'sharp right': _('Turn right', 'direction'),
uturn: _('Turn back', 'direction'),
};

const context = {
modifier: stringifyModifier[maneuver.modifier],
name: maneuver.detail.name,
};

return maneuver.detail.name ? _('{modifier} on {name}', 'direction', context) : context.modifier;
};
import { walkingManeuver } from 'src/libs/route_utils';

const PublicTransportWalkLeg = ({ leg }) => {
const [detailsOpen, setDetailsOpen] = useState(false);
Expand All @@ -41,7 +23,7 @@ const PublicTransportWalkLeg = ({ leg }) => {
'itinerary_roadmap_item--walk',
!hasSteps && 'itinerary_roadmap_item--no-hover'
)}
line={<LegLine mode="WALK" />}
line={<DefaultLegLine mode="WALK" />}
distance={formatDuration(leg.duration)}
type="WALK"
>
Expand All @@ -62,7 +44,7 @@ const PublicTransportWalkLeg = ({ leg }) => {
<div className="itinerary_roadmap_substeps">
{leg.steps.map((step, index) => (
<div key={index} className="itinerary_roadmap_substep">
<div>{step.maneuver.instruction || stringifyManeuver(step.maneuver)}</div>
<div>{step.maneuver.instruction || walkingManeuver(step.maneuver)}</div>
</div>
))}
</div>
Expand Down
17 changes: 0 additions & 17 deletions src/panel/direction/RoutesList/Route/RoadMap/RoadMapStep/index.jsx

This file was deleted.

51 changes: 0 additions & 51 deletions src/panel/direction/RoutesList/Route/RoadMap/WalkLeg/index.jsx

This file was deleted.

Loading