1
- import { memo } from 'react' ;
1
+ import { memo , useEffect } from 'react' ;
2
2
import classnames from 'classnames' ;
3
3
import { entries , sortBy } from 'lodash' ;
4
4
@@ -28,16 +28,17 @@ function renderTiming(time: NextBusTime) {
28
28
}
29
29
30
30
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 ) {
32
37
return (
33
38
< >
34
- < h3 className = { styles . heading } > { props . name } </ h3 >
39
+ < h3 className = { styles . heading } > { name } </ h3 >
35
40
< 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 ) } >
41
42
Retry
42
43
</ button >
43
44
</ >
@@ -49,26 +50,24 @@ export const ArrivalTimes = memo<Props>((props: Props) => {
49
50
50
51
return (
51
52
< >
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 >
72
71
73
72
< button
74
73
type = "button"
0 commit comments