Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Jun 7, 2024
2 parents 5532d64 + 3b6c184 commit 87b1a86
Showing 1 changed file with 60 additions and 17 deletions.
77 changes: 60 additions & 17 deletions src/components/AmeyLiveTrainAnnouncements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,20 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
['', 'none', 'three', 'four'].includes(val),
)
const [hasEnabledFeature, setHasEnabledFeature] = useState(false)
const [useLegacyTocNames, setUseLegacyTocNames] = useStateWithLocalStorage<boolean>('amey.live-trains.use-legacy-toc-names', false)
const [announceViaPoints, setAnnounceViaPoints] = useStateWithLocalStorage<boolean>(
'amey.live-trains.announce-vias',
true,
x => x === true || x === false,
)
const [useLegacyTocNames, setUseLegacyTocNames] = useStateWithLocalStorage<boolean>(
'amey.live-trains.use-legacy-toc-names',
false,
x => x === true || x === false,
)
const [showUnconfirmedPlatforms, setShowUnconfirmedPlatforms] = useStateWithLocalStorage<boolean>(
'amey.live-trains.show-unconfirmed-platforms',
false,
x => x === true || x === false,
)
const [isPlaying, setIsPlaying] = useState(false)
const [enabledAnnouncements, setEnabledAnnouncements] = useStateWithLocalStorage<AnnouncementType[]>('amey.live-trains.announcement-types', [
Expand Down Expand Up @@ -543,7 +553,9 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
)

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)

Expand Down Expand Up @@ -581,11 +593,12 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
} catch (e) {
console.warn(`[Live Trains] Error playing announcement for ${train.rid}; see below`)
console.error(e)
} finally {
console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`)
setTimeout(() => setIsPlaying(false), 5000)
}
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(
Expand All @@ -611,7 +624,9 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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,
Expand Down Expand Up @@ -643,11 +658,22 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
} catch (e) {
console.warn(`[Live Trains] Error playing announcement for ${train.rid}; see below`)
console.error(e)
} finally {
console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`)
setTimeout(() => setIsPlaying(false), 5000)
}
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(
Expand All @@ -674,7 +700,9 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
)

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,
Expand Down Expand Up @@ -707,11 +735,12 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
} catch (e) {
console.warn(`[Live Trains] Error playing announcement for ${train.rid}; see below`)
console.error(e)
} finally {
console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`)
setTimeout(() => setIsPlaying(false), 5000)
}
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(
Expand All @@ -735,7 +764,9 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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

Expand Down Expand Up @@ -796,11 +827,12 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
}

console.error(e)
} finally {
console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`)
setTimeout(() => setIsPlaying(false), 5000)
}
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(() => {
Expand Down Expand Up @@ -1135,6 +1167,17 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
Use legacy TOC names
</label>

<label htmlFor="announce-vias">
<input
type="checkbox"
name="announce-vias"
id="announce-vias"
checked={announceViaPoints}
onChange={e => setAnnounceViaPoints(e.target.checked)}
/>
Announce via points
</label>

<label htmlFor="chime-type-select" className="option-select">
Chime
<Select<Option<ChimeType | ''>, false>
Expand Down

0 comments on commit 87b1a86

Please sign in to comment.