Skip to content

Commit

Permalink
refactor: route viewer always use route color overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Oct 11, 2023
1 parent ea10904 commit 4968d66
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
53 changes: 30 additions & 23 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import { generateModeSettingValues } from '../util/api'
import {
getActiveItineraries,
getActiveItinerary,
getRouteOperator,
queryIsValid
} from '../util/state'
import {
getColorAndNameFromRoute,
getRouteColorBasedOnSettings
} from '../util/viewer'
import { ItineraryView } from '../util/ui'

import {
Expand Down Expand Up @@ -669,6 +674,10 @@ export const findRoute = (params) =>
newRoute.patterns = routePatterns
// TODO: avoid explicit behavior shift like this
newRoute.v2 = true
newRoute.color = getColorAndNameFromRoute(
getRouteOperator(route, getState().otp.config.transitOperators),
route
).backgroundColor.split('#')[1]
newRoute.mode = checkForRouteModeOverride(
newRoute,
getState().otp.config?.routeModeOverrides
Expand Down Expand Up @@ -716,29 +725,27 @@ export function findRoutes() {
const { config } = getState().otp
// To initialize the route viewer,
// convert the routes array to a dictionary indexed by route ids.
return routes.reduce(
(
result,
{ agency, color, id, longName, mode, shortName, type }
) => {
result[id] = {
agencyId: agency.id,
agencyName: agency.name,
color,
id,
longName,
mode: checkForRouteModeOverride(
{ id, mode },
config?.routeModeOverrides
),
shortName,
type,
v2: true
}
return result
},
{}
)
return routes.reduce((result, route) => {
const { agency, id, longName, mode, shortName, type } = route
result[id] = {
agencyId: agency.id,
agencyName: agency.name,
color: getColorAndNameFromRoute(
getRouteOperator(route, config.transitOperators),
route
).backgroundColor.split('#')[1],
id,
longName,
mode: checkForRouteModeOverride(
{ id, mode },
config?.routeModeOverrides
),
shortName,
type,
v2: true
}
return result
}, {})
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion lib/util/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export function getColorAndNameFromRoute(operator, route) {
const modeColors = operator?.modeColors?.[getModeFromRoute(route)]

const backgroundColor = `#${
modeColors?.color || defaultRouteColor || route.color || '333333'
modeColors?.color || defaultRouteColor || route?.color || '333333'
}`
// NOTE: text color is not a part of short response route object, so there
// is no way to determine from OTP what the text color should be if the
Expand Down

0 comments on commit 4968d66

Please sign in to comment.