-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathStopAlerts.js
More file actions
117 lines (108 loc) · 3.18 KB
/
StopAlerts.js
File metadata and controls
117 lines (108 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import PropTypes from 'prop-types';
import React from 'react';
import { intlShape } from 'react-intl';
import AlertList from './AlertList';
import DepartureCancelationInfo from './DepartureCancelationInfo';
import {
getCancelationsForStop,
getServiceAlertsForStop,
otpServiceAlertShape,
getServiceAlertsForStopRoutes,
getServiceAlertsForTerminalStops,
routeHasServiceAlert,
getServiceAlertsForRoute,
routeHasCancelation,
getCancelationsForRoute,
} from '../util/alertUtils.ts';
const StopAlerts = ({ stop }, { intl }) => {
const cancelations = getCancelationsForStop(stop).map(stoptime => {
const { color, mode, shortName } = stoptime.trip.route;
const departureTime = stoptime.serviceDay + stoptime.scheduledDeparture;
return {
header: (
<DepartureCancelationInfo
firstStopName={stoptime.trip.stops[0].name}
headsign={stoptime.headsign}
routeMode={mode}
scheduledDepartureTime={departureTime}
shortName={shortName}
/>
),
route: {
color,
mode,
shortName,
},
validityPeriod: {
startTime: departureTime,
},
};
});
const serviceAlertsForRoutes = [];
const disruptionsForRoutes = [];
if (stop.routes) {
stop.routes.forEach(
route =>
routeHasServiceAlert(route) &&
serviceAlertsForRoutes.push(
...getServiceAlertsForRoute(route, route.gtfsId, intl.locale),
) &&
routeHasCancelation(route) &&
disruptionsForRoutes.push(
...getCancelationsForRoute(route, route.gtfsId, intl.locale),
),
);
}
const isTerminal = !stop.code;
const serviceAlerts = [
// Alerts for terminal's stops.
...getServiceAlertsForTerminalStops(isTerminal, stop, intl.locale),
...getServiceAlertsForStop(stop, intl.locale),
...getServiceAlertsForStopRoutes(stop, intl.locale),
...serviceAlertsForRoutes,
...disruptionsForRoutes,
];
return (
<AlertList
showRouteNameLink={false}
cancelations={cancelations}
serviceAlerts={serviceAlerts}
/>
);
};
StopAlerts.propTypes = {
stop: PropTypes.shape({
name: PropTypes.string,
code: PropTypes.string,
routes: PropTypes.array,
alerts: PropTypes.arrayOf(otpServiceAlertShape).isRequired,
stoptimes: PropTypes.arrayOf(
PropTypes.shape({
headsign: PropTypes.string.isRequired,
realtimeState: PropTypes.string,
scheduledDeparture: PropTypes.number,
serviceDay: PropTypes.number,
trip: PropTypes.shape({
pattern: PropTypes.shape({
code: PropTypes.string,
}),
route: PropTypes.shape({
alerts: PropTypes.arrayOf(otpServiceAlertShape).isRequired,
color: PropTypes.string,
mode: PropTypes.string.isRequired,
shortName: PropTypes.string.isRequired,
}).isRequired,
stops: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
}),
).isRequired,
}).isRequired,
}),
).isRequired,
}).isRequired,
};
StopAlerts.contextTypes = {
intl: intlShape.isRequired,
};
export default StopAlerts;