Skip to content

Commit be46fcb

Browse files
committed
fix bike_scenic profile and fallback if no icon
1 parent ffc19f8 commit be46fcb

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/sidebar/MobileSidebar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Coordinate } from '@/utils'
1616
import PlainButton from '@/PlainButton'
1717
import { tr } from '@/translation/Translation'
1818
import Chevron from '@/sidebar/search/routingProfiles/chevron.svg'
19-
import { icons } from '@/sidebar/search/routingProfiles/profileIcons'
19+
import { findIcon } from '@/sidebar/search/routingProfiles/profileIcons'
2020
import { RoutingProfile } from '@/api/graphhopper'
2121

2222
type MobileSidebarProps = {
@@ -102,8 +102,7 @@ function SmallSearchView(props: { points: QueryPoint[]; selectedProfile: Routing
102102
const from = props.points[0]
103103
const to = props.points[props.points.length - 1]
104104
const isSmallHeight = useMediaQuery({ query: '(max-height: 36rem)' })
105-
const icon = icons[props.selectedProfile.name]
106-
const iconElement = icon ? React.createElement(icon) : React.createElement(icons.question_mark)
105+
const iconElement = React.createElement(findIcon(props.selectedProfile.name))
107106

108107
return (
109108
<div className={styles.btnOpenContainer} onClick={props.onClick}>
Lines changed: 42 additions & 0 deletions
Loading

src/sidebar/search/routingProfiles/profileIcons.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import BicycleIcon from './bike.svg'
2+
import BikeScenicIcon from './bike_scenic.svg'
23
import CarIcon from './car.svg'
34
import FootIcon from './foot.svg'
45
import HikeIcon from './hike.svg'
@@ -25,6 +26,7 @@ export const icons: Record<string, any> = {
2526
foot: FootIcon,
2627
hike: HikeIcon,
2728
bike: BicycleIcon,
29+
bike_scenic: BikeScenicIcon,
2830
mtb: MtbBicycleIcon, // Mountainbike
2931
racingbike: RacingbikeIcon,
3032
ecargobike: EcargobikeIcon,
@@ -35,3 +37,11 @@ export const icons: Record<string, any> = {
3537
car_avoid_ferry: FerryDisabledIcon,
3638
car_avoid_toll: TollDisabledIcon,
3739
}
40+
41+
// Resolve an icon for a routing-profile name. Falls back to the base-profile icon for custom profiles
42+
// like 'bike_scenic' → 'bike', and finally to the question-mark icon if nothing matches.
43+
export function findIcon(profileName: string): any {
44+
if (icons[profileName]) return icons[profileName]
45+
const baseKey = Object.keys(icons).find(k => profileName.startsWith(k + '_'))
46+
return baseKey ? icons[baseKey] : icons.question_mark
47+
}

0 commit comments

Comments
 (0)