@@ -4,6 +4,7 @@ import { entries, sortBy } from 'lodash';
4
4
5
5
import { RefreshCw as Refresh } from 'react-feather' ;
6
6
import { BusTiming , NextBus , NextBusTime } from 'types/venues' ;
7
+ import { simplifyRouteName , extractRouteStyle } from 'utils/venues' ;
7
8
import styles from './BusStops.scss' ;
8
9
9
10
type Props = BusTiming & {
@@ -12,17 +13,6 @@ type Props = BusTiming & {
12
13
reload : ( code : string ) => void ;
13
14
} ;
14
15
15
- /**
16
- * Extract the route name from the start of a string
17
- */
18
- const routes = [ 'A1' , 'A2' , 'B1' , 'B2' , 'C' , 'D1' , 'D2' , 'BTC1' , 'BTC2' ] ;
19
- export function extractRoute ( route : string ) {
20
- for ( let i = 0 ; i < routes . length ; i ++ ) {
21
- if ( route . startsWith ( routes [ i ] ) ) return routes [ i ] ;
22
- }
23
- return null ;
24
- }
25
-
26
16
/**
27
17
* Adds 'min' to numeric timings and highlight any buses that are arriving
28
18
* soon with a <strong> tag
@@ -37,15 +27,6 @@ function renderTiming(time: NextBusTime) {
37
27
return time ;
38
28
}
39
29
40
- /**
41
- * Route names with parenthesis in them don't have a space in front of the
42
- * opening bracket, causing the text to wrap weirdly. This forces the opening
43
- * paren to always have a space in front of it.
44
- */
45
- function fixRouteName ( name : string ) {
46
- return name . replace ( / \s ? \( / , ' (' ) ;
47
- }
48
-
49
30
export const ArrivalTimes = memo < Props > ( ( props : Props ) => {
50
31
if ( props . error ) {
51
32
return (
@@ -72,15 +53,14 @@ export const ArrivalTimes = memo<Props>((props: Props) => {
72
53
{ props . timings && (
73
54
< table className = { classnames ( styles . timings , 'table table-sm' ) } >
74
55
< tbody >
75
- { timings . map ( ( [ routeName , timing ] : [ string , NextBus ] ) => {
76
- const route = extractRoute ( routeName ) ;
77
- const className = route
78
- ? classnames ( styles . routeHeading , styles [ `route${ route } ` ] )
79
- : '' ;
80
-
56
+ { timings . map ( ( [ route , timing ] : [ string , NextBus ] ) => {
57
+ const className = classnames (
58
+ styles . routeHeading ,
59
+ styles [ `route${ extractRouteStyle ( route ) } ` ] ,
60
+ ) ;
81
61
return (
82
- < tr key = { routeName } >
83
- < th className = { className } > { fixRouteName ( routeName ) } </ th >
62
+ < tr key = { route } >
63
+ < th className = { className } > { simplifyRouteName ( route ) } </ th >
84
64
< td > { renderTiming ( timing . arrivalTime ) } </ td >
85
65
< td > { renderTiming ( timing . nextArrivalTime ) } </ td >
86
66
</ tr >
@@ -104,3 +84,5 @@ export const ArrivalTimes = memo<Props>((props: Props) => {
104
84
</ >
105
85
) ;
106
86
} ) ;
87
+
88
+ export default ArrivalTimes ;
0 commit comments