Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-6547 fix accumulating departure rows #5164

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions app/component/DepartureListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const asDepartures = stoptimes =>
(!canceled
? stoptime.realtimeDeparture
: stoptime.scheduledDeparture);
const stoptimeTime = isArrival ? arrivalTime : departureTime;
const time = isArrival ? arrivalTime : departureTime;

const { pattern } = stoptime.trip;
return {
Expand All @@ -60,7 +60,7 @@ const asDepartures = stoptimes =>
hasNoStop,
hasOnlyDropoff,
isLastStop,
stoptime: stoptimeTime,
time,
stop: stoptime.stop,
realtime: stoptime.realtime,
pattern,
Expand Down Expand Up @@ -246,21 +246,21 @@ class DepartureListContainer extends Component {
let dayCutoff = moment.unix(currentTime).startOf('day').unix();
const departures = asDepartures(stoptimes)
.filter(departure => !(isTerminal && departure.isArrival))
.filter(departure => currentTime < departure.stoptime)
.filter(departure => currentTime < departure.time)
.slice(0, limit);

// Add day dividers when day changes and add service day divider after service day changes.
// If day divider and service day dividers are added with same departure only show day divider.
const departuresWithDayDividers = departures.map(departure => {
const serviceDate = moment.unix(departure.serviceDay).format('DDMMYYYY');
const dayCutoffDate = moment.unix(dayCutoff).format('DDMMYYYY');
const stoptimeDate = moment.unix(departure.stoptime).format('DDMMYYYY');
const date = moment.unix(departure.time).format('DDMMYYYY');
const serviceDayCutoffDate = moment
.unix(serviceDayCutoff)
.format('DDMMYYYY');

if (stoptimeDate !== dayCutoffDate && departure.stoptime > dayCutoff) {
dayCutoff = moment.unix(departure.stoptime).startOf('day').unix();
if (date !== dayCutoffDate && departure.time > dayCutoff) {
dayCutoff = moment.unix(departure.time).startOf('day').unix();
// eslint-disable-next-line no-param-reassign
departure.addDayDivider = true;
}
Expand All @@ -283,14 +283,14 @@ class DepartureListContainer extends Component {

let firstDayDepartureCount = 0;
departuresWithDayDividers.forEach((departure, index) => {
const departureDate = moment.unix(departure.stoptime).format('DDMMYYYY');
const departureDate = moment.unix(departure.time).format('DDMMYYYY');
const nextDay = moment.unix(currentTime).add(1, 'day').unix();
if (departure.stoptime < nextDay) {
if (departure.time < nextDay) {
firstDayDepartureCount += 1;
}

// If next 24h has more than 10 departures only show stops for the next 24h
if (departure.stoptime > nextDay && firstDayDepartureCount >= 10) {
if (departure.time > nextDay && firstDayDepartureCount >= 10) {
return;
}

Expand All @@ -299,7 +299,7 @@ class DepartureListContainer extends Component {
<tr key={departureDate}>
<td colSpan={isTerminal ? 4 : 3}>
<div className="date-row border-bottom">
{moment.unix(departure.stoptime).format('dddd D.M.YYYY')}
{moment.unix(departure.time).format('dddd D.M.YYYY')}
</div>
</td>
</tr>,
Expand All @@ -314,7 +314,7 @@ class DepartureListContainer extends Component {
);
}

const id = `${departure.pattern.code}:${departure.stoptime}`;
const id = `${departure.pattern.code}:${departure.time}:${departure.trip.gtfsId}`;
const dropoffMessage = getDropoffMessage(
departure.hasOnlyDropoff,
departure.hasNoStop,
Expand Down Expand Up @@ -344,7 +344,7 @@ class DepartureListContainer extends Component {
<DepartureRow
key={id}
departure={row}
departureTime={departure.stoptime}
departureTime={departure.time}
currentTime={this.props.currentTime}
showPlatformCode={isTerminal}
canceled={departure.canceled}
Expand Down
Loading