diff --git a/app/component/itinerary/NaviCard.js b/app/component/itinerary/NaviCard.js
new file mode 100644
index 0000000000..e7e89f48e3
--- /dev/null
+++ b/app/component/itinerary/NaviCard.js
@@ -0,0 +1,60 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { legShape } from '../../util/shapes';
+import Icon from '../Icon';
+import { isRental } from '../../util/legUtils';
+import NaviInstructions from './NaviInstructions';
+import NaviCardExtension from './NaviCardExtension';
+
+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',
+};
+
+export default function NaviCard({ leg, nextLeg, legType, cardExpanded }) {
+ 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') {
+ instructions = `navileg-rent-scooter`;
+ } else {
+ instructions = `navileg-rent-cycle`;
+ }
+ }
+ return (
+
+ );
+}
+
+NaviCard.propTypes = {
+ leg: legShape.isRequired,
+ nextLeg: legShape.isRequired,
+ legType: PropTypes.string.isRequired,
+ cardExpanded: PropTypes.bool,
+};
+NaviCard.defaultProps = {
+ cardExpanded: false,
+};
diff --git a/app/component/itinerary/NaviTop.js b/app/component/itinerary/NaviCardContainer.js
similarity index 63%
rename from app/component/itinerary/NaviTop.js
rename to app/component/itinerary/NaviCardContainer.js
index 09cf2a89d3..9d65cf630b 100644
--- a/app/component/itinerary/NaviTop.js
+++ b/app/component/itinerary/NaviCardContainer.js
@@ -4,8 +4,7 @@ import { FormattedMessage, intlShape } from 'react-intl';
import distance from '@digitransit-search-util/digitransit-search-util-distance';
import { legShape, configShape } from '../../util/shapes';
import { legTime, legTimeStr } from '../../util/legUtils';
-import NaviLeg from './NaviLeg';
-import Icon from '../Icon';
+import NaviCard from './NaviCard';
import NaviStack from './NaviStack';
import {
getItineraryAlerts,
@@ -22,12 +21,12 @@ function getFirstLastLegs(legs) {
return { first, last };
}
-function NaviTop(
+function NaviCardContainer(
{ focusToLeg, time, realTimeLegs, position },
{ intl, config },
) {
const [currentLeg, setCurrentLeg] = useState(null);
- const [showMessages, setShowMessages] = useState(true);
+ const [cardExpanded, setCardExpanded] = useState(false);
// All notifications including those user has dismissed.
const [messages, setMessages] = useState(new Map());
// notifications that are shown to the user.
@@ -37,17 +36,9 @@ function NaviTop(
const destCountRef = useRef(0);
const handleClick = () => {
- setShowMessages(!showMessages);
+ setCardExpanded(!cardExpanded);
};
- useEffect(() => {
- const timer = setTimeout(() => {
- setShowMessages(false);
- }, 5000);
-
- return () => clearTimeout(timer);
- }, []);
-
useEffect(() => {
const newLeg = realTimeLegs.find(leg => {
return legTime(leg.start) <= time && time <= legTime(leg.end);
@@ -68,21 +59,17 @@ function NaviTop(
const l = currentLeg || newLeg;
if (l) {
- const nextTransitLeg = realTimeLegs.find(
- leg => legTime(leg.start) > legTime(l.start) && leg.transitLeg,
+ const nextLeg = realTimeLegs.find(
+ leg => legTime(leg.start) > legTime(l.start),
);
- if (nextTransitLeg) {
+ if (nextLeg?.transitLeg) {
// Messages for NaviStack.
- const transitLegState = getTransitLegState(
- nextTransitLeg,
- intl,
- messages,
- );
+ const transitLegState = getTransitLegState(nextLeg, intl, messages);
if (transitLegState) {
incomingMessages.set(transitLegState.id, transitLegState);
}
const additionalMsgs = getAdditionalMessages(
- nextTransitLeg,
+ nextLeg,
time,
intl,
config,
@@ -94,42 +81,50 @@ function NaviTop(
});
}
}
-
- if (legChanged) {
+ if (newLeg) {
focusToLeg?.(newLeg);
- setCurrentLeg(newLeg);
}
-
- if (incomingMessages.size || legChanged) {
- // Handle messages when new messages arrives or leg is changed.
-
- // Current active messages. Filter away legChange messages when leg changes.
- const currActiveMessages = legChanged
- ? activeMessages.filter(m => m.expiresOn !== 'legChange')
- : activeMessages;
-
- const newMessages = Array.from(incomingMessages.values());
- setActiveMessages([...currActiveMessages, ...newMessages]);
- setMessages(new Map([...messages, ...incomingMessages]));
-
- setShowMessages(true);
+ if (legChanged) {
+ setCurrentLeg(newLeg);
+ setCardExpanded(false);
}
+ }
+ if (incomingMessages.size || legChanged) {
+ // Handle messages when new messages arrives or leg is changed.
+
+ // Current active messages. Filter away legChange messages when leg changes.
+ const previousValidMessages = legChanged
+ ? activeMessages.filter(m => m.expiresOn !== 'legChange')
+ : activeMessages;
+
+ // handle messages that are updated.
+ const updatedMessages = previousValidMessages.map(msg => {
+ const incoming = incomingMessages.get(msg.id);
+ if (incoming) {
+ incomingMessages.delete(msg.id);
+ return incoming;
+ }
+ return msg;
+ });
+ const newMessages = Array.from(incomingMessages.values());
+ setActiveMessages([...updatedMessages, ...newMessages]);
+ setMessages(new Map([...messages, ...incomingMessages]));
+ }
- if (!focusRef.current && focusToLeg) {
- // handle initial focus when not tracking
- if (newLeg) {
- focusToLeg(newLeg);
- destCountRef.current = 0;
+ if (!focusRef.current && focusToLeg) {
+ // handle initial focus when not tracking
+ if (newLeg) {
+ focusToLeg(newLeg);
+ destCountRef.current = 0;
+ } else {
+ const { first, last } = getFirstLastLegs(realTimeLegs);
+ if (time < legTime(first.start)) {
+ focusToLeg(first);
} else {
- const { first, last } = getFirstLastLegs(realTimeLegs);
- if (time < legTime(first.start)) {
- focusToLeg(first);
- } else {
- focusToLeg(last);
- }
+ focusToLeg(last);
}
- focusRef.current = true;
}
+ focusRef.current = true;
}
// User position and distance from currentleg endpoint.
@@ -160,16 +155,20 @@ function NaviTop(
const nextLeg = realTimeLegs.find(leg => {
return legTime(leg.start) > legTime(currentLeg.start);
});
+ let legType;
if (destCountRef.current >= TIME_AT_DESTINATION) {
- // User at the destination. show wait message.
- naviTopContent = (
-
- );
+ legType = 'wait';
} else {
- naviTopContent = (
-
- );
+ legType = 'move';
}
+ naviTopContent = (
+
+ );
} else {
naviTopContent = `Tracking ${currentLeg?.mode} leg`;
}
@@ -182,25 +181,19 @@ function NaviTop(
setActiveMessages(activeMessages.filter((_, i) => i !== index));
};
- const showmessages = activeMessages.length > 0;
return (
<>
-