To display the arrival time on top and the departure time just below it in a single column for each station, we need to modify the structure of the stationDiv in the JavaScript code. The following modifications (in the script part) should accomplish this:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
tripDetails.appendChild(tripSummary);
let vehicleDiv = document.createElement("div");
// vehicleDiv.textContent = `Vehicle Number: ${trip.vehicle_number}, Trip: ${trip.trip}`;
scheduleContainer.appendChild(vehicleDiv);
let hasDeparted = false;
let hasArrived = false;
trip.stations.forEach((station, stationIndex) => {
let stationDiv = document.createElement("div");
stationDiv.classList.add("station");
if (station.station.toUpperCase().startsWith(departure)) {
hasDeparted = true;
}
let arrivalTimeDiv = document.createElement("div");
arrivalTimeDiv.classList.add("station-time");
if (hasDeparted && !hasArrived) {
arrivalTimeDiv.classList.add("green-bg");
}
arrivalTimeDiv.textContent = station.arrivalTime;
stationDiv.appendChild(arrivalTimeDiv);
stationDiv.classList.add(
"px-4",
"py-2",
"border-b",
"flex",
"justify-between",
"items-center",
"last:border-b-0"
);
let timeWrapperDiv = document.createElement("div");
timeWrapperDiv.classList.add("time-wrapper");
let hoiDiv = document.createElement("div");
hoiDiv.classList.add("hoi");
if (hasDeparted && !hasArrived) {
hoiDiv.classList.add("green-border");
}
timeWrapperDiv.appendChild(hoiDiv);
if (stationIndex !== trip.stations.length - 1) {
let timelineDiv = document.createElement("div");
timelineDiv.classList.add("timeline");
if (
hasDeparted &&
!hasArrived &&
station.station.toUpperCase().startsWith(destination) === false
) {
timelineDiv.classList.add("green-line");
} else {
timelineDiv.classList.add("blue-line");
}
timeWrapperDiv.appendChild(timelineDiv);
}
stationDiv.appendChild(timeWrapperDiv);
let stationNameDiv = document.createElement("div");
stationNameDiv.classList.add("station-name");
stationNameDiv.textContent = station.station;
stationDiv.appendChild(stationNameDiv);
let departureTimeDiv = document.createElement("div");
departureTimeDiv.classList.add("station-time");
if (hasDeparted && !hasArrived) {
departureTimeDiv.classList.add("green-bg");
}
departureTimeDiv.textContent = station.departureTime;
stationDiv.appendChild(departureTimeDiv);
scheduleContainer.appendChild(stationDiv);
if (station.station.toUpperCase().startsWith(destination)) {
hasArrived = true;
}
tripDetails.appendChild(stationDiv);
});
scheduleContainer.appendChild(tripDetails);
});
}
</script>
Update the .station CSS class to have a column rather than a row flex direction.
Refactor the JavaScript code to use a .time-column class and place both the arrival and departure time in a single column.
Adjust the HTML structure accordingly when creating the elements within the trip.stations.forEach loop.
Here is the updated JavaScript function updateSchedule, and only the parts that have changed are displayed:
javascript
function updateSchedule(scheduleData, departure, destination) {
// ...
trip.stations.forEach((station, stationIndex) => {
let stationDiv = document.createElement("div");
stationDiv.classList.add("station");
// ...
let timeColumnDiv = document.createElement("div");
timeColumnDiv.classList.add("time-column");
let arrivalTimeDiv = document.createElement("div");
arrivalTimeDiv.classList.add("station-time");
arrivalTimeDiv.textContent = station.arrivalTime;
timeColumnDiv.appendChild(arrivalTimeDiv);
// ... (Add the Hoi and Timeline divs here)
let departureTimeDiv = document.createElement("div");
departureTimeDiv.classList.add("station-time");
departureTimeDiv.textContent = station.departureTime;
timeColumnDiv.appendChild(departureTimeDiv);
stationDiv.appendChild(timeColumnDiv);
// ...
tripDetails.appendChild(stationDiv);
});
scheduleContainer.appendChild(tripDetails);
}
And the CSS changes:
css
.station {
flex-direction: column; /* instead of row */
align-items: flex-start; /* align to start */
}
.time-column {
display: flex;
flex-direction: column;
}
.station-name {
order: 3; /* push the station name below the times */
}
.station-time {
margin-right: 0; /* reset the margin if needed */
}
Please note, I've only shown snippets of the function and the CSS that you'll need to adapt. It assumes you understand where these changes fit into your existing code. Implement these changes within your existing code where appropriate. Consider that some styles and classes may need to be refactored or renamed to better suit your new layout.