@@ -3,15 +3,87 @@ import { BaseSettingsSection } from '../components/BaseSettingsSection';
33import { InputWidgetSettings } from '../types' ;
44import { useDashboard } from '@irdashies/context' ;
55import { ToggleSwitch } from '../components/ToggleSwitch' ;
6- import { InputSettings as InputSettingsType } from '../../Input/InputContainer/InputContainer' ;
6+
7+ const SETTING_ID = 'input' ;
8+
9+ const defaultConfig : InputWidgetSettings [ 'config' ] = {
10+ trace : {
11+ enabled : true ,
12+ includeThrottle : true ,
13+ includeBrake : true ,
14+ } ,
15+ bar : {
16+ enabled : true ,
17+ includeClutch : true ,
18+ includeBrake : true ,
19+ includeThrottle : true ,
20+ } ,
21+ gear : {
22+ enabled : true ,
23+ unit : 'auto' ,
24+ } ,
25+ steer : {
26+ enabled : true ,
27+ } ,
28+ } ;
29+
30+ // Migration function to handle missing properties in the new config format
31+ const migrateConfig = (
32+ savedConfig : unknown ,
33+ ) : InputWidgetSettings [ 'config' ] => {
34+ if ( ! savedConfig || typeof savedConfig !== 'object' ) return defaultConfig ;
35+
36+ const config = savedConfig as Record < string , unknown > ;
37+
38+ return {
39+ trace : {
40+ enabled :
41+ ( config . trace as { enabled ?: boolean } ) ?. enabled ??
42+ defaultConfig . trace . enabled ,
43+ includeThrottle :
44+ ( config . trace as { includeThrottle ?: boolean } ) ?. includeThrottle ??
45+ defaultConfig . trace . includeThrottle ,
46+ includeBrake :
47+ ( config . trace as { includeBrake ?: boolean } ) ?. includeBrake ??
48+ defaultConfig . trace . includeBrake ,
49+ } ,
50+ bar : {
51+ enabled :
52+ ( config . bar as { enabled ?: boolean } ) ?. enabled ?? defaultConfig . bar . enabled ,
53+ includeClutch :
54+ ( config . bar as { includeClutch ?: boolean } ) ?. includeClutch ??
55+ defaultConfig . bar . includeClutch ,
56+ includeBrake :
57+ ( config . bar as { includeBrake ?: boolean } ) ?. includeBrake ??
58+ defaultConfig . bar . includeBrake ,
59+ includeThrottle :
60+ ( config . bar as { includeThrottle ?: boolean } ) ?. includeThrottle ??
61+ defaultConfig . bar . includeThrottle ,
62+ } ,
63+ gear : {
64+ enabled :
65+ ( config . gear as { enabled ?: boolean } ) ?. enabled ??
66+ defaultConfig . gear . enabled ,
67+ unit :
68+ ( config . gear as { unit ?: 'mph' | 'km/h' | 'auto' } ) ?. unit ??
69+ defaultConfig . gear . unit ,
70+ } ,
71+ steer : {
72+ enabled :
73+ ( config . steer as { enabled ?: boolean } ) ?. enabled ??
74+ defaultConfig . steer . enabled ,
75+ } ,
76+ } ;
77+ } ;
778
879export const InputSettings = ( ) => {
980 const { currentDashboard } = useDashboard ( ) ;
81+ const savedSettings = currentDashboard ?. widgets . find (
82+ ( w ) => w . id === SETTING_ID ,
83+ ) ;
1084 const [ settings , setSettings ] = useState < InputWidgetSettings > ( {
11- enabled :
12- currentDashboard ?. widgets . find ( ( w ) => w . id === 'input' ) ?. enabled ?? false ,
13- config : ( ( currentDashboard ?. widgets . find ( ( w ) => w . id === 'input' )
14- ?. config as unknown ) as InputSettingsType ) ,
85+ enabled : savedSettings ?. enabled ?? false ,
86+ config : migrateConfig ( savedSettings ?. config ) ,
1587 } ) ;
1688
1789 if ( ! currentDashboard ) {
@@ -21,7 +93,7 @@ export const InputSettings = () => {
2193 const config = settings . config ;
2294
2395 return (
24- < BaseSettingsSection < InputSettingsType >
96+ < BaseSettingsSection
2597 title = "Input Traces Settings"
2698 description = "Configure the input traces display settings for throttle, brake, and clutch."
2799 settings = { settings }
@@ -135,6 +207,26 @@ export const InputSettings = () => {
135207 ) }
136208 </ div >
137209
210+ { /* Steer Settings */ }
211+ < div className = "space-y-4" >
212+ < div className = "flex items-center justify-between" >
213+ < h3 className = "text-lg font-medium text-slate-200" >
214+ Steer Settings
215+ </ h3 >
216+ < div className = "flex items-center gap-3" >
217+ < span className = "text-sm text-slate-300" >
218+ Enable Steer Display
219+ </ span >
220+ < ToggleSwitch
221+ enabled = { config . steer . enabled }
222+ onToggle = { ( enabled ) =>
223+ handleConfigChange ( { steer : { ...config . steer , enabled } } )
224+ }
225+ />
226+ </ div >
227+ </ div >
228+ </ div >
229+
138230 { /* Gear Settings */ }
139231 < div className = "space-y-4" >
140232 < div className = "flex items-center justify-between" >
0 commit comments