From cad43d980b8ddbcfc9dfaf1377f6346c05b23a12 Mon Sep 17 00:00:00 2001 From: Janne Antikainen Date: Mon, 16 Dec 2024 12:44:52 +0200 Subject: [PATCH] do not fetch itinerarypage topics when in navigator mode update topics in navigator so that only relevant vehicles are shown add wait img back --- app/component/itinerary/ItineraryPage.js | 8 +++++--- app/component/itinerary/ItineraryPageUtils.js | 6 +++--- app/component/itinerary/navigator/NaviCard.js | 2 ++ .../itinerary/navigator/NaviCardContainer.js | 20 ++++++++++++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/component/itinerary/ItineraryPage.js b/app/component/itinerary/ItineraryPage.js index f550defea3..ebc3d961c0 100644 --- a/app/component/itinerary/ItineraryPage.js +++ b/app/component/itinerary/ItineraryPage.js @@ -831,13 +831,14 @@ export default function ItineraryPage(props, context) { const selected = combinedEdges.length ? combinedEdges[selectedIndex] : null; - const itineraryTopics = getTopics(selected, config); + + const itineraryTopics = getTopics(selected?.node.legs, config); const { client } = context.getStore('RealTimeInformationStore'); // Client may not be initialized yet if there was an client before ComponentDidMount - if (!isEqual(itineraryTopics, topicsState) || !client) { + if (!naviMode && (!isEqual(itineraryTopics, topicsState) || !client)) { updateClient(itineraryTopics, context); } - if (!isEqual(itineraryTopics, topicsState)) { + if (!isEqual(itineraryTopics, topicsState) && !naviMode) { // eslint-disable-next-line react/no-did-update-set-state setTopicsState(itineraryTopics); } @@ -852,6 +853,7 @@ export default function ItineraryPage(props, context) { altStates[PLANTYPE.PARKANDRIDE][0].plan, location.state?.selectedItineraryIndex, relaxScooterState.plan, + naviMode, ]); useEffect(() => { diff --git a/app/component/itinerary/ItineraryPageUtils.js b/app/component/itinerary/ItineraryPageUtils.js index 74408fd4fd..d48171d14d 100644 --- a/app/component/itinerary/ItineraryPageUtils.js +++ b/app/component/itinerary/ItineraryPageUtils.js @@ -87,13 +87,13 @@ export function addFeedbackly(context) { } } -export function getTopics(itinerary, config) { +export function getTopics(legs, config) { const itineraryTopics = []; - if (itinerary) { + if (legs) { const { realTime, feedIds } = config; - itinerary.node.legs.forEach(leg => { + legs.forEach(leg => { if (leg.transitLeg && leg.trip) { const feedId = leg.trip.gtfsId.split(':')[0]; let topic; diff --git a/app/component/itinerary/navigator/NaviCard.js b/app/component/itinerary/navigator/NaviCard.js index 00658ff9ba..75eaac285f 100644 --- a/app/component/itinerary/navigator/NaviCard.js +++ b/app/component/itinerary/navigator/NaviCard.js @@ -62,6 +62,8 @@ export default function NaviCard( } else if (legType === LEGTYPE.MOVE) { instructions = `navileg-${leg?.mode.toLowerCase()}`; iconName = iconMap.WALK; + } else if (legType === LEGTYPE.WAIT) { + iconName = iconMap.WAIT; } return ( diff --git a/app/component/itinerary/navigator/NaviCardContainer.js b/app/component/itinerary/navigator/NaviCardContainer.js index 89366f9817..5527eac903 100644 --- a/app/component/itinerary/navigator/NaviCardContainer.js +++ b/app/component/itinerary/navigator/NaviCardContainer.js @@ -13,6 +13,7 @@ import { getTransitLegState, LEGTYPE, } from './NaviUtils'; +import { updateClient, getTopics } from '../ItineraryPageUtils'; const DESTINATION_RADIUS = 20; // meters const TIME_AT_DESTINATION = 3; // * 10 seconds @@ -37,7 +38,7 @@ function NaviCardContainer( lastLeg, isJourneyCompleted, }, - { intl, config, match, router }, + context, ) { const [cardExpanded, setCardExpanded] = useState(false); // All notifications including those user has dismissed. @@ -51,7 +52,7 @@ function NaviCardContainer( // Destination counter. How long user has been at the destination. * 10 seconds const destCountRef = useRef(0); const cardRef = useRef(null); - + const { intl, config, match, router } = context; const handleRemove = index => { setActiveMessages(activeMessages.filter((_, i) => i !== index)); }; @@ -60,6 +61,16 @@ function NaviCardContainer( setCardExpanded(!cardExpanded); }; + // track only relevant vehicles for the journey. + const topics = getTopics( + legs.filter(leg => legTime(leg.end) >= time), + config, + ); + + useEffect(() => { + updateClient(topics, context); + }, []); + useEffect(() => { if (cardRef.current) { const contentHeight = cardRef.current.getBoundingClientRect(); @@ -74,7 +85,6 @@ function NaviCardContainer( const legChanged = legRef.current?.legId ? legRef.current.legId !== currentLeg?.legId : legRef.current?.mode !== currentLeg?.mode; - if (legChanged) { legRef.current = currentLeg; } @@ -93,7 +103,9 @@ function NaviCardContainer( ...getAdditionalMessages(nextLeg, time, intl, config, messages), ]); } + if (legChanged) { + updateClient(topics, context); focusToLeg?.(currentLeg); setCardExpanded(false); } @@ -241,6 +253,8 @@ NaviCardContainer.contextTypes = { config: configShape.isRequired, match: matchShape.isRequired, router: routerShape.isRequired, + executeAction: PropTypes.func.isRequired, + getStore: PropTypes.func.isRequired, }; export default NaviCardContainer;