1- import { SetVehicleProfile , UpdateSettings } from '@/actions/Actions'
1+ import { SetVehicleProfile , UpdateSettings } from '@/actions/Actions'
22import Dispatcher from '@/stores/Dispatcher'
33import styles from '@/sidebar/SettingsBox.module.css'
4- import { tr } from '@/translation/Translation'
4+ import { tr } from '@/translation/Translation'
55import PlainButton from '@/PlainButton'
66import OnIcon from '@/sidebar/toggle_on.svg'
77import OffIcon from '@/sidebar/toggle_off.svg'
8- import { useContext , useState } from 'react'
9- import { SettingsContext } from '@/contexts/SettingsContext'
10- import { RoutingProfile } from '@/api/graphhopper'
8+ import { useContext } from 'react'
9+ import { SettingsContext } from '@/contexts/SettingsContext'
10+ import { RoutingProfile } from '@/api/graphhopper'
11+ import { ProfileGroupMap } from "@/stores/QueryStore" ;
12+ import * as config from "config" ;
1113
12- export default function SettingsBox ( { profile } : { profile : RoutingProfile } ) {
14+ export default function SettingsBox ( { profile} : { profile : RoutingProfile } ) {
1315 const settings = useContext ( SettingsContext )
16+
1417 function setProfile ( n : string ) {
15- Dispatcher . dispatch ( new SetVehicleProfile ( { name : profile . name === n ? 'car' : n } ) )
18+ Dispatcher . dispatch ( new SetVehicleProfile ( { name : profile . name === n ? 'car' : n } ) )
1619 }
1720
21+ const groupName = ProfileGroupMap . create ( config . profile_group_mapping ) [ profile . name ]
22+ const group = config . profile_group_mapping [ groupName ]
1823 return (
1924 < div className = { styles . parent } >
25+ { groupName && < span className = { styles . groupProfileOptionsHeader } >
26+ { tr ( group . settings_tr_key ) }
27+ </ span > }
28+ { groupName && < div className = { styles . settingsTable } >
29+ < div className = { styles . groupProfileOptions } >
30+ { group . options . map ( ( option ) => (
31+ < div key = { option . profile } >
32+ < input checked = { profile . name === option . profile } type = "radio" id = { option . profile }
33+ name = { groupName } value = { option . profile }
34+ onClick = { ( ) => setProfile ( option . profile ) } />
35+ < label htmlFor = { option . profile } >
36+ { tr ( group . settings_tr_key + '_' + option . profile ) }
37+ </ label >
38+ </ div >
39+ ) ) }
40+ </ div >
41+ </ div > }
2042 < div className = { styles . title } > { tr ( 'settings' ) } </ div >
2143 < div className = { styles . settingsTable } >
22- { /* TODO make generic so that it could be used to collapse e.g. hike & foot */ }
23- { profile . name . startsWith ( 'car' ) && (
24- < div className = { styles . carProfileOptions } >
25- < span className = { styles . carProfileOptionsHeader } > { tr ( 'Avoid' ) } </ span >
26- < div >
27- { /*prettier-ignore*/ }
28- < input checked = { profile . name === 'car_avoid_motorway' } type = "radio" id = "motorway" name = "car" value = "motorway" onClick = { e => setProfile ( 'car_avoid_motorway' ) } />
29- < label htmlFor = "motorway" > { tr ( 'motorway' ) } </ label >
30- </ div >
31- < div >
32- { /*prettier-ignore*/ }
33- < input checked = { profile . name === 'car_avoid_ferry' } type = "radio" id = "ferry" name = "car" value = "ferry" onClick = { e => setProfile ( 'car_avoid_ferry' ) } />
34- < label htmlFor = "ferry" > { tr ( 'ferry' ) } </ label >
35- </ div >
36- < div >
37- { /*prettier-ignore*/ }
38- < input checked = { profile . name === 'car_avoid_toll' } type = "radio" id = "toll" name = "car" value = "toll" onClick = { e => setProfile ( 'car_avoid_toll' ) } />
39- < label htmlFor = "toll" > { tr ( 'toll and ferry' ) } </ label >
40- </ div >
41- </ div >
42- ) }
4344 < SettingsToggle
4445 title = { tr ( 'distance_unit' , [ tr ( settings . showDistanceInMiles ? 'mi' : 'km' ) ] ) }
4546 enabled = { settings . showDistanceInMiles }
4647 onClick = { ( ) =>
47- Dispatcher . dispatch ( new UpdateSettings ( { showDistanceInMiles : ! settings . showDistanceInMiles } ) )
48+ Dispatcher . dispatch ( new UpdateSettings ( { showDistanceInMiles : ! settings . showDistanceInMiles } ) )
4849 }
4950 />
5051 </ div >
@@ -55,23 +56,23 @@ export default function SettingsBox({ profile }: { profile: RoutingProfile }) {
5556 title = { tr ( 'settings_gpx_export_trk' ) }
5657 enabled = { settings . gpxExportTrk }
5758 onClick = { ( ) =>
58- Dispatcher . dispatch ( new UpdateSettings ( { gpxExportTrk : ! settings . gpxExportTrk } ) )
59+ Dispatcher . dispatch ( new UpdateSettings ( { gpxExportTrk : ! settings . gpxExportTrk } ) )
5960 }
6061 />
6162
6263 < SettingsCheckbox
6364 title = { tr ( 'settings_gpx_export_rte' ) }
6465 enabled = { settings . gpxExportRte }
6566 onClick = { ( ) =>
66- Dispatcher . dispatch ( new UpdateSettings ( { gpxExportRte : ! settings . gpxExportRte } ) )
67+ Dispatcher . dispatch ( new UpdateSettings ( { gpxExportRte : ! settings . gpxExportRte } ) )
6768 }
6869 />
6970
7071 < SettingsCheckbox
7172 title = { tr ( 'settings_gpx_export_wpt' ) }
7273 enabled = { settings . gpxExportWpt }
7374 onClick = { ( ) =>
74- Dispatcher . dispatch ( new UpdateSettings ( { gpxExportWpt : ! settings . gpxExportWpt } ) )
75+ Dispatcher . dispatch ( new UpdateSettings ( { gpxExportWpt : ! settings . gpxExportWpt } ) )
7576 }
7677 />
7778 </ div >
@@ -87,22 +88,23 @@ export default function SettingsBox({ profile }: { profile: RoutingProfile }) {
8788 )
8889}
8990
90- function SettingsToggle ( { title, enabled, onClick } : { title : string ; enabled : boolean ; onClick : ( ) => void } ) {
91+ function SettingsToggle ( { title, enabled, onClick} : { title : string ; enabled : boolean ; onClick : ( ) => void } ) {
9192 return (
9293 < div className = { styles . settingsToggle } onClick = { onClick } >
93- < PlainButton style = { { color : enabled ? '' : 'lightgray' } } className = { styles . toggleButton } >
94- { enabled ? < OnIcon /> : < OffIcon /> }
94+ < PlainButton style = { { color : enabled ? '' : 'lightgray' } } className = { styles . toggleButton } >
95+ { enabled ? < OnIcon /> : < OffIcon /> }
9596 </ PlainButton >
96- < div style = { { color : enabled ? '#5b616a' : 'gray' } } > { title } </ div >
97+ < div style = { { color : enabled ? '#5b616a' : 'gray' } } > { title } </ div >
9798 </ div >
9899 )
99100}
100101
101- function SettingsCheckbox ( { title, enabled, onClick } : { title : string ; enabled : boolean ; onClick : ( ) => void } ) {
102+ function SettingsCheckbox ( { title, enabled, onClick} : { title : string ; enabled : boolean ; onClick : ( ) => void } ) {
102103 return (
103104 < div className = { styles . settingsCheckbox } onClick = { onClick } >
104- < input type = "checkbox" checked = { enabled } onChange = { ignore => { } } > </ input >
105- < label style = { { color : enabled ? '#5b616a' : 'gray' } } > { title } </ label >
105+ < input type = "checkbox" checked = { enabled } onChange = { ignore => {
106+ } } > </ input >
107+ < label style = { { color : enabled ? '#5b616a' : 'gray' } } > { title } </ label >
106108 </ div >
107109 )
108110}
0 commit comments