@@ -186,9 +186,70 @@ class IndexPage extends React.Component {
186
186
} ${ this . context . config . trafficNowLink [ lang ] } `;
187
187
} ;
188
188
189
+ clickStopNearIcon = ( url , kbdEvent ) => {
190
+ if ( kbdEvent && ! isKeyboardSelectionEvent ( kbdEvent ) ) {
191
+ return ;
192
+ }
193
+ this . context . router . push ( url ) ;
194
+ } ;
195
+
196
+ NearStops ( CtrlPanel ) {
197
+ const { intl, config } = this . context ;
198
+ const { colors, fontWeights } = config ;
199
+ const { lang } = this . props ;
200
+ const transportModes = getTransportModes ( config ) ;
201
+ const nearYouModes = getNearYouModes ( config ) ;
202
+
203
+ // Styles are defined by which button type is configured (narrow/wide)
204
+ const narrowButtons = config . narrowNearYouButtons ;
205
+ const modeTitles = filterObject (
206
+ transportModes ,
207
+ 'availableForSelection' ,
208
+ true ,
209
+ ) ;
210
+ // If nearYouModes is configured, display those. Otherwise, display all configured transport modes
211
+ const modes =
212
+ nearYouModes ?. length > 0 ? nearYouModes : Object . keys ( modeTitles ) ;
213
+
214
+ const alertsContext = {
215
+ currentTime : this . props . currentTime ,
216
+ getModesWithAlerts,
217
+ feedIds : config . feedIds ,
218
+ } ;
219
+
220
+ return config . showNearYouButtons ? (
221
+ < CtrlPanel . NearStopsAndRoutes
222
+ modeArray = { modes }
223
+ urlPrefix = { `/${ PREFIX_NEARYOU } ` }
224
+ language = { lang }
225
+ showTitle
226
+ alertsContext = { alertsContext }
227
+ origin = { this . props . origin }
228
+ omitLanguageUrl
229
+ onClick = { this . clickStopNearIcon }
230
+ buttonStyle = { narrowButtons ? undefined : config . nearYouButton }
231
+ title = { narrowButtons ? undefined : config . nearYouTitle }
232
+ modes = { narrowButtons ? undefined : modeTitles }
233
+ modeSet = { config . nearbyModeSet || config . iconModeSet }
234
+ modeIconColors = { colors . iconColors }
235
+ fontWeights = { fontWeights }
236
+ />
237
+ ) : (
238
+ < div className = "stops-near-you-text" >
239
+ < h2 >
240
+ { ' ' }
241
+ { intl . formatMessage ( {
242
+ id : 'stop-near-you-title' ,
243
+ defaultMessage : 'Stops and lines near you' ,
244
+ } ) }
245
+ </ h2 >
246
+ </ div >
247
+ ) ;
248
+ }
249
+
189
250
/* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
190
251
render ( ) {
191
- const { intl, config, router } = this . context ;
252
+ const { intl, config } = this . context ;
192
253
const { trafficNowLink, colors, fontWeights } = config ;
193
254
const color = colors . primary ;
194
255
const hoverColor = colors . hover || LightenDarkenColor ( colors . primary , - 20 ) ;
@@ -218,12 +279,6 @@ class IndexPage extends React.Component {
218
279
'MapPosition' ,
219
280
] ;
220
281
221
- const alertsContext = {
222
- currentTime : this . props . currentTime ,
223
- getModesWithAlerts,
224
- feedIds : config . feedIds ,
225
- } ;
226
-
227
282
const showSpinner =
228
283
( origin . type === 'CurrentLocation' && ! origin . address ) ||
229
284
( destination . type === 'CurrentLocation' && ! destination . address ) ;
@@ -249,7 +304,7 @@ class IndexPage extends React.Component {
249
304
onGeolocationStart : this . onSelectLocation ,
250
305
fromMap : this . props . fromMap ,
251
306
fontWeights,
252
- modeIconColors : config . colors . iconColors ,
307
+ modeIconColors : colors . iconColors ,
253
308
modeSet : config . iconModeSet ,
254
309
} ;
255
310
@@ -269,7 +324,7 @@ class IndexPage extends React.Component {
269
324
sources,
270
325
targets : stopAndRouteSearchTargets ,
271
326
fontWeights,
272
- modeIconColors : config . colors . iconColors ,
327
+ modeIconColors : colors . iconColors ,
273
328
modeSet : config . iconModeSet ,
274
329
geocodingSize : 25 ,
275
330
} ;
@@ -282,60 +337,6 @@ class IndexPage extends React.Component {
282
337
results . filter ( config . stopSearchFilter ) ;
283
338
}
284
339
285
- const transportModes = getTransportModes ( config ) ;
286
- const nearYouModes = getNearYouModes ( config ) ;
287
-
288
- // TODO this probably needs refactoring as nested components are against best practices
289
- // eslint-disable-next-line react/no-unstable-nested-components
290
- const NearStops = CtrlPanel => {
291
- // Styles are defined by which button type is configured (narrow/wide)
292
- const narrowButtons = config . narrowNearYouButtons ;
293
- const modeTitles = filterObject (
294
- transportModes ,
295
- 'availableForSelection' ,
296
- true ,
297
- ) ;
298
- // If nearYouModes is configured, display those. Otherwise, display all configured transport modes
299
- const modes =
300
- nearYouModes ?. length > 0 ? nearYouModes : Object . keys ( modeTitles ) ;
301
-
302
- const clickStopNearIcon = ( url , kbdEvent ) => {
303
- if ( kbdEvent && ! isKeyboardSelectionEvent ( kbdEvent ) ) {
304
- return ;
305
- }
306
- router . push ( url ) ;
307
- } ;
308
-
309
- return config . showNearYouButtons ? (
310
- < CtrlPanel . NearStopsAndRoutes
311
- modeArray = { modes }
312
- urlPrefix = { `/${ PREFIX_NEARYOU } ` }
313
- language = { lang }
314
- showTitle
315
- alertsContext = { alertsContext }
316
- origin = { origin }
317
- omitLanguageUrl
318
- onClick = { clickStopNearIcon }
319
- buttonStyle = { narrowButtons ? undefined : config . nearYouButton }
320
- title = { narrowButtons ? undefined : config . nearYouTitle }
321
- modes = { narrowButtons ? undefined : modeTitles }
322
- modeSet = { config . nearbyModeSet || config . iconModeSet }
323
- modeIconColors = { config . colors . iconColors }
324
- fontWeights = { fontWeights }
325
- />
326
- ) : (
327
- < div className = "stops-near-you-text" >
328
- < h2 >
329
- { ' ' }
330
- { intl . formatMessage ( {
331
- id : 'stop-near-you-title' ,
332
- defaultMessage : 'Stops and lines near you' ,
333
- } ) }
334
- </ h2 >
335
- </ div >
336
- ) ;
337
- } ;
338
-
339
340
return (
340
341
< LazilyLoad modules = { modules } >
341
342
{ ( {
@@ -394,7 +395,7 @@ class IndexPage extends React.Component {
394
395
395
396
{ ! config . hideStopRouteSearch && (
396
397
< >
397
- < > { NearStops ( CtrlPanel ) } </ >
398
+ < > { this . NearStops ( CtrlPanel ) } </ >
398
399
< StopRouteSearch { ...stopRouteSearchProps } /> { ' ' }
399
400
< CtrlPanel . SeparatorLine />
400
401
</ >
@@ -444,7 +445,7 @@ class IndexPage extends React.Component {
444
445
isMobile
445
446
/>
446
447
< CtrlPanel . SeparatorLine />
447
- < > { NearStops ( CtrlPanel ) } </ >
448
+ < > { this . NearStops ( CtrlPanel ) } </ >
448
449
< div className = "stop-route-search-container" >
449
450
< StopRouteSearch isMobile { ...stopRouteSearchProps } />
450
451
</ div >
0 commit comments