Prepare code for Eurostar/Trenitalia France/RENFE/ÖBB data input
This commit is contained in:
@ -107,7 +107,11 @@ function TrainRow({train, tableType, date, time}) {
|
||||
enabled: !!trip.route,
|
||||
})
|
||||
const route = routeQuery.data ?? {}
|
||||
const trainType = getTrainType(train, route)
|
||||
const trainType = getTrainType(train, trip, route)
|
||||
const backgroundColor = getBackgroundColor(train, trip, route)
|
||||
console.log(backgroundColor)
|
||||
const textColor = getTextColor(train, trip, route)
|
||||
const trainTypeDisplay = getTrainTypeDisplay(trainType)
|
||||
|
||||
const stopTimesQuery = useQuery({
|
||||
queryKey: ['stop_times', trip.id],
|
||||
@ -151,7 +155,6 @@ function TrainRow({train, tableType, date, time}) {
|
||||
const delay = tableType === "departures" ? realtimeData.departure_delay : realtimeData.arrival_delay
|
||||
const prettyDelay = delay && scheduleRelationship !== 3 ? getPrettyDelay(delay) : ""
|
||||
const [prettyScheduleRelationship, scheduleRelationshipColor] = getPrettyScheduleRelationship(scheduleRelationship)
|
||||
console.log(realtimeTripData)
|
||||
|
||||
let stopsFilter
|
||||
if (scheduleRelationship === 3)
|
||||
@ -174,9 +177,9 @@ function TrainRow({train, tableType, date, time}) {
|
||||
height="4em"
|
||||
borderRadius="15%"
|
||||
fontWeight="bold"
|
||||
backgroundColor={`#${getBackgroundColor(train, route)}`}
|
||||
color={`#${getTextColor(train, route)}`}>
|
||||
{trainType}
|
||||
backgroundColor={backgroundColor}
|
||||
color={textColor}>
|
||||
{trainTypeDisplay}
|
||||
</Box>
|
||||
</div>
|
||||
</TableCell>
|
||||
@ -211,46 +214,99 @@ function TrainRow({train, tableType, date, time}) {
|
||||
</>
|
||||
}
|
||||
|
||||
function getTrainType(train, route) {
|
||||
if (train.id.startsWith("IDFM"))
|
||||
return route.short_name
|
||||
else {
|
||||
let trainType = train.stop.split("StopPoint:OCE")[1].split("-")[0]
|
||||
if (trainType === "Train TER")
|
||||
trainType = "TER"
|
||||
else if (trainType === "INTERCITES")
|
||||
trainType = "INTER-CITÉS"
|
||||
else if (trainType === "INTERCITES de nuit")
|
||||
trainType = "INTER-CITÉS de nuit"
|
||||
return trainType
|
||||
function getTrainType(train, trip, route) {
|
||||
switch (route.transport_type) {
|
||||
case "TGV":
|
||||
case "TER":
|
||||
case "IC":
|
||||
let trainType = train.stop.split("StopPoint:OCE")[1].split("-")[0]
|
||||
switch (trainType) {
|
||||
case "Train TER":
|
||||
return "TER"
|
||||
case "INTERCITES":
|
||||
return "INTER-CITÉS"
|
||||
case "INTERCITES de nuit":
|
||||
return "INTER-CITÉS de nuit"
|
||||
default:
|
||||
return trainType
|
||||
}
|
||||
case "TN":
|
||||
return route.short_name
|
||||
case "ES":
|
||||
return "Eurostar"
|
||||
case "TI":
|
||||
return "Trenitalia"
|
||||
case "RENFE":
|
||||
return "RENFE"
|
||||
case "OBB":
|
||||
if (trip.short_name.startsWith("NJ"))
|
||||
return "NJ"
|
||||
return "ÖBB"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function getBackgroundColor(train, route) {
|
||||
if (route.color)
|
||||
return route.color
|
||||
else if (getTrainType(train, route) === "OUIGO")
|
||||
return "E60075"
|
||||
return "FFFFFF"
|
||||
function getTrainTypeDisplay(trainType) {
|
||||
switch (trainType) {
|
||||
case "TGV INOUI":
|
||||
return <img src="/tgv_inoui.svg" alt="TGV INOUI" width="80%" />
|
||||
case "OUIGO":
|
||||
return <img src="/ouigo.svg" alt="OUIGO" width="80%" />
|
||||
case "TER":
|
||||
return <img src="/ter.svg" alt="TER" width="80%" />
|
||||
case "Car TER":
|
||||
return <div><img src="/bus.svg" alt="Car" width="40%" />
|
||||
<br/>
|
||||
<img src="/ter.svg" alt="TER" width="40%" /></div>
|
||||
case "ICE":
|
||||
return <img src="/ice.svg" alt="ICE" width="80%" />
|
||||
case "Eurostar":
|
||||
return <img src="/eurostar_mini.svg" alt="Eurostar" width="80%" />
|
||||
case "Trenitalia":
|
||||
return <img src="/trenitalia.svg" alt="Frecciarossa" width="80%" />
|
||||
case "RENFE":
|
||||
return <img src="/renfe.svg" alt="RENFE" width="80%" />
|
||||
case "NJ":
|
||||
return <img src="/nightjet.svg" alt="NightJet" width="80%" />
|
||||
default:
|
||||
return trainType
|
||||
}
|
||||
}
|
||||
|
||||
function getTextColor(train, route) {
|
||||
function getBackgroundColor(train, trip, route) {
|
||||
let trainType = getTrainType(train, trip, route)
|
||||
switch (trainType) {
|
||||
case "OUIGO":
|
||||
return "#0096CA"
|
||||
case "Eurostar":
|
||||
return "#00286A"
|
||||
case "NJ":
|
||||
return "#272759"
|
||||
default:
|
||||
if (route.color)
|
||||
return `#${route.color}`
|
||||
return "#FFFFFF"
|
||||
}
|
||||
}
|
||||
|
||||
function getTextColor(train, trip, route) {
|
||||
if (route.text_color)
|
||||
return route.text_color
|
||||
return `#${route.text_color}`
|
||||
else {
|
||||
let trainType = getTrainType(train, route)
|
||||
let trainType = getTrainType(train, trip, route)
|
||||
switch (trainType) {
|
||||
case "OUIGO":
|
||||
return "FFFFFF"
|
||||
return "#FFFFFF"
|
||||
case "TGV INOUI":
|
||||
return "9B2743"
|
||||
return "#9B2743"
|
||||
case "ICE":
|
||||
return "B4B4B4"
|
||||
return "#B4B4B4"
|
||||
case "INTER-CITÉS":
|
||||
case "INTER-CITÉS de nuit":
|
||||
return "404042"
|
||||
return "#404042"
|
||||
default:
|
||||
return "000000"
|
||||
return "#000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user