Manage trip additions and cancels

This commit is contained in:
2024-02-06 08:01:56 +01:00
parent 9ed97df4b5
commit 8d2ffe3014
7 changed files with 247 additions and 149 deletions

View File

@ -131,12 +131,14 @@ function TrainRow({train, tableType, date, time}) {
let headline = stops[tableType === "departures" ? stops.length - 1 : 0]?.stop ?? {name: "Chargement…"}
let stopsFilter
if (tableType === "departures")
stopsFilter = (stop_time) => stop_time.stop_sequence > train.stop_sequence && stop_time.drop_off_type === 0
else
stopsFilter = (stop_time) => stop_time.stop_sequence < train.stop_sequence && stop_time.pickup_type === 0
let stopsNames = stops.filter(stopsFilter).map(stopTime => stopTime?.stop.name ?? "").join(", ") ?? ""
const realtimeTripQuery = useQuery({
queryKey: ['realtimeTrip', trip.id, date, time],
queryFn: () => fetch(`/api/gtfs-rt/trip_update/${trip.id}/`)
.then(response => response.json()),
enabled: !!trip.id,
})
const realtimeTripData = realtimeTripQuery.data ?? {}
const scheduleRelationship = realtimeTripData.schedule_relationship ?? 0
const realtimeQuery = useQuery({
queryKey: ['realtime', train.id, date, time],
@ -145,11 +147,20 @@ function TrainRow({train, tableType, date, time}) {
enabled: !!train.id,
})
const realtimeData = realtimeQuery.data ?? {}
if (!realtimeQuery.isError)
console.log(realtimeData)
const delay = tableType === "departures" ? realtimeData.departure_delay : realtimeData.arrival_delay
const prettyDelay = delay ? getPrettyDelay(delay) : ""
const visibleDelay = delay ? `${prettyDelay}` : ""
const prettyDelay = delay && scheduleRelationship !== 3 ? getPrettyDelay(delay) : ""
const [prettyScheduleRelationship, scheduleRelationshipColor] = getPrettyScheduleRelationship(scheduleRelationship)
console.log(realtimeTripData)
let stopsFilter
if (scheduleRelationship === 3)
stopsFilter = (stop_time) => true
else if (tableType === "departures")
stopsFilter = (stop_time) => stop_time.stop_sequence > train.stop_sequence && stop_time.drop_off_type === 0
else
stopsFilter = (stop_time) => stop_time.stop_sequence < train.stop_sequence && stop_time.pickup_type === 0
let stopsNames = stops.filter(stopsFilter).map(stopTime => stopTime?.stop.name ?? "").join(", ") ?? ""
return <>
<StyledTableRow tabletype={tableType}>
@ -184,7 +195,10 @@ function TrainRow({train, tableType, date, time}) {
{getDisplayTime(train, tableType)}
</Box>
<Box color={delay && delay !== "00:00:00" ? "#e86d2b" : "white"} fontWeight={delay && delay !== "00:00:00" ? "bold" : ""}>
{visibleDelay}
{prettyDelay}
</Box>
<Box color={scheduleRelationshipColor} fontWeight="bold">
{prettyScheduleRelationship}
</Box>
</Box>
</Box>
@ -255,4 +269,15 @@ function getPrettyDelay(delay) {
return full_minutes ? `+${full_minutes} min` : "À l'heure"
}
function getPrettyScheduleRelationship(scheduledRelationship) {
switch (scheduledRelationship) {
case 1:
return ["Ajouté", "#3ebb18"]
case 3:
return ["Supprimé", "#ff8701"]
default:
return ["", ""]
}
}
export default TrainsTable;