Skip to content

Commit c7638e1

Browse files
committed
website: bus: Load arrival timings when opening a route marker
1 parent 4cf991d commit c7638e1

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

website/src/views/components/map/ArrivalTimes.tsx

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo } from 'react';
1+
import { memo, useEffect } from 'react';
22
import classnames from 'classnames';
33
import { entries, sortBy } from 'lodash';
44

@@ -28,16 +28,17 @@ function renderTiming(time: NextBusTime) {
2828
}
2929

3030
export const ArrivalTimes = memo<Props>((props: Props) => {
31-
if (props.error) {
31+
const { reload, code, name, error } = props;
32+
useEffect(() => {
33+
reload(code);
34+
}, [reload, code]);
35+
36+
if (error) {
3237
return (
3338
<>
34-
<h3 className={styles.heading}>{props.name}</h3>
39+
<h3 className={styles.heading}>{name}</h3>
3540
<p>Error loading arrival times</p>
36-
<button
37-
type="button"
38-
className="btn btn-sm btn-primary"
39-
onClick={() => props.reload(props.code)}
40-
>
41+
<button type="button" className="btn btn-sm btn-primary" onClick={() => reload(code)}>
4142
Retry
4243
</button>
4344
</>
@@ -49,26 +50,24 @@ export const ArrivalTimes = memo<Props>((props: Props) => {
4950

5051
return (
5152
<>
52-
<h3 className={styles.heading}>{props.name}</h3>
53-
{props.timings && (
54-
<table className={classnames(styles.timings, 'table table-sm')}>
55-
<tbody>
56-
{timings.map(([route, timing]: [string, NextBus]) => {
57-
const className = classnames(
58-
styles.routeHeading,
59-
styles[`route${extractRouteStyle(route)}`],
60-
);
61-
return (
62-
<tr key={route}>
63-
<th className={className}>{simplifyRouteName(route)}</th>
64-
<td>{renderTiming(timing.arrivalTime)}</td>
65-
<td>{renderTiming(timing.nextArrivalTime)}</td>
66-
</tr>
67-
);
68-
})}
69-
</tbody>
70-
</table>
71-
)}
53+
<h3 className={styles.heading}>{name}</h3>
54+
<table className={classnames(styles.timings, 'table table-sm')}>
55+
<tbody>
56+
{timings.map(([route, timing]: [string, NextBus]) => {
57+
const className = classnames(
58+
styles.routeHeading,
59+
styles[`route${extractRouteStyle(route)}`],
60+
);
61+
return (
62+
<tr key={route}>
63+
<th className={className}>{simplifyRouteName(route)}</th>
64+
<td>{renderTiming(timing.arrivalTime)}</td>
65+
<td>{renderTiming(timing.nextArrivalTime)}</td>
66+
</tr>
67+
);
68+
})}
69+
</tbody>
70+
</table>
7271

7372
<button
7473
type="button"

0 commit comments

Comments
 (0)