From 4a2877cc574c8afe66e4ac87c984cd010624b483 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Fri, 7 Jun 2024 12:57:28 +0100 Subject: [PATCH] feat: add option to disable via points in live trains --- src/components/AmeyLiveTrainAnnouncements.tsx | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/components/AmeyLiveTrainAnnouncements.tsx b/src/components/AmeyLiveTrainAnnouncements.tsx index 7898bb7d2..03ee44be7 100644 --- a/src/components/AmeyLiveTrainAnnouncements.tsx +++ b/src/components/AmeyLiveTrainAnnouncements.tsx @@ -373,10 +373,20 @@ export function LiveTrainAnnouncements({ ['', 'none', 'three', 'four'].includes(val), ) const [hasEnabledFeature, setHasEnabledFeature] = useState(false) - const [useLegacyTocNames, setUseLegacyTocNames] = useStateWithLocalStorage('amey.live-trains.use-legacy-toc-names', false) + const [announceViaPoints, setAnnounceViaPoints] = useStateWithLocalStorage( + 'amey.live-trains.announce-vias', + true, + x => x === true || x === false, + ) + const [useLegacyTocNames, setUseLegacyTocNames] = useStateWithLocalStorage( + 'amey.live-trains.use-legacy-toc-names', + false, + x => x === true || x === false, + ) const [showUnconfirmedPlatforms, setShowUnconfirmedPlatforms] = useStateWithLocalStorage( 'amey.live-trains.show-unconfirmed-platforms', false, + x => x === true || x === false, ) const [isPlaying, setIsPlaying] = useState(false) const [enabledAnnouncements, setEnabledAnnouncements] = useStateWithLocalStorage('amey.live-trains.announcement-types', [ @@ -543,7 +553,9 @@ export function LiveTrainAnnouncements({ ) const callingAt = getCallingPoints(train, systems[systemKey].STATIONS, loc => getStation(loc, systemKey)) - const [vias] = getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + const [vias] = announceViaPoints + ? getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + : [[]] const mindTheGap = isMindTheGapStation(selectedCrs, train.platform) @@ -585,7 +597,7 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markNextTrainAnnounced, systems, setIsPlaying, standingTrainHandler, selectedCrs, getStation, addLog, useLegacyTocNames], + [markNextTrainAnnounced, systems, setIsPlaying, standingTrainHandler, selectedCrs, getStation, addLog, useLegacyTocNames, announceViaPoints], ) const announceApproachingTrain = useCallback( @@ -611,7 +623,9 @@ export function LiveTrainAnnouncements({ useLegacyTocNames, ) - const vias = getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + const vias = announceViaPoints + ? getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + : [[]] const options: ILiveTrainApproachingAnnouncementOptions = { chime: chimeType || systems[systemKey].DEFAULT_CHIME, @@ -647,7 +661,17 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markNextTrainAnnounced, systems, setIsPlaying, approachingTrainHandler, getStation, addLog, useLegacyTocNames, chimeType], + [ + markNextTrainAnnounced, + systems, + setIsPlaying, + approachingTrainHandler, + getStation, + addLog, + useLegacyTocNames, + chimeType, + announceViaPoints, + ], ) const announceNextTrain = useCallback( @@ -674,7 +698,9 @@ export function LiveTrainAnnouncements({ ) const callingAt = getCallingPoints(train, systems[systemKey].STATIONS, loc => getStation(loc, systemKey)) - const [vias] = getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + const [vias] = announceViaPoints + ? getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + : [[]] const options: INextTrainAnnouncementOptions = { chime: chimeType || systems[systemKey].DEFAULT_CHIME, @@ -711,7 +737,7 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markNextTrainAnnounced, systems, setIsPlaying, nextTrainHandler, getStation, addLog, useLegacyTocNames, chimeType], + [markNextTrainAnnounced, systems, setIsPlaying, nextTrainHandler, getStation, addLog, useLegacyTocNames, chimeType, announceViaPoints], ) const announceDisruptedTrain = useCallback( @@ -735,7 +761,9 @@ export function LiveTrainAnnouncements({ useLegacyTocNames, ) - const [vias] = getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + const [vias] = announceViaPoints + ? getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) + : [[]] let delayReason: string[] | null = null @@ -800,7 +828,7 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markDisruptedTrainAnnounced, systems, setIsPlaying, disruptedTrainHandler, addLog, useLegacyTocNames, chimeType], + [markDisruptedTrainAnnounced, systems, setIsPlaying, disruptedTrainHandler, addLog, useLegacyTocNames, chimeType, announceViaPoints], ) useEffect(() => { @@ -1135,6 +1163,17 @@ export function LiveTrainAnnouncements({ Use legacy TOC names + +