Restore time display
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
function TrainsTable({stop, tableType}) {
|
||||
function TrainsTable({stop, date, time, tableType}) {
|
||||
let tableClass = tableType === "departures" ? "table-departures" : "table-arrivals"
|
||||
tableClass = `table table-striped ${tableClass}`
|
||||
return <>
|
||||
<table className={tableClass}>
|
||||
<TrainsTableHeader />
|
||||
<TrainsTableBody stop={stop} tableType={tableType} />
|
||||
<TrainsTableBody stop={stop} date={date} time={time} tableType={tableType} />
|
||||
</table>
|
||||
</>
|
||||
}
|
||||
@ -21,19 +21,19 @@ function TrainsTableHeader() {
|
||||
</thead>
|
||||
}
|
||||
|
||||
function TrainsTableBody({stop, tableType}) {
|
||||
function TrainsTableBody({stop, date, time, tableType}) {
|
||||
const [trains, setTrains] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
if (stop.id !== undefined) {
|
||||
fetch(`http://localhost:8000/api/station/next_${tableType}/?stop_id=${stop.id}&format=json`)
|
||||
fetch(`http://localhost:8000/api/station/next_${tableType}/?stop_id=${stop.id}&date=${date}&time=${time}&format=json`)
|
||||
.then(response => response.json())
|
||||
.then(data => data.results)
|
||||
.then(data => {
|
||||
setTrains(data)
|
||||
})
|
||||
}
|
||||
}, [stop, tableType])
|
||||
}, [stop, tableType, date, time])
|
||||
|
||||
let table_rows = trains.map((train) => <TrainRow train={train} tableType={tableType} />)
|
||||
|
||||
@ -127,7 +127,7 @@ function TrainRow({train, tableType}) {
|
||||
</td>
|
||||
<td>
|
||||
<div className="table-hour d-flex align-items-center justify-content-center text-time fw-bold h-100">
|
||||
{train.departure_time}
|
||||
{getDisplayTime(train, tableType)}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
@ -182,4 +182,10 @@ function getTextColor(train, route) {
|
||||
}
|
||||
}
|
||||
|
||||
function getDisplayTime(train, tableType) {
|
||||
let time = tableType === "departures" ? train.departure_time : train.arrival_time
|
||||
let day_split = time.split(' ')
|
||||
return day_split[day_split.length - 1].substring(0, 5)
|
||||
}
|
||||
|
||||
export default TrainsTable;
|
Reference in New Issue
Block a user