@@ -3,11 +3,28 @@ import { BaseSettingsSection } from '../components/BaseSettingsSection';
33import  {  WeatherWidgetSettings  }  from  '../types' ; 
44import  {  useDashboard  }  from  '@irdashies/context' ; 
55
6+ const  SETTING_ID  =  'weather' ; 
7+ 
8+ const  defaultConfig : WeatherWidgetSettings [ 'config' ]  =  { 
9+   background : {  opacity : 0  } , 
10+ } ; 
11+ 
12+ const  migrateConfig  =  ( savedConfig : unknown ) : WeatherWidgetSettings [ 'config' ]  =>  { 
13+   if  ( ! savedConfig  ||  typeof  savedConfig  !==  'object' )  return  defaultConfig ; 
14+   const  config  =  savedConfig  as  Record < string ,  unknown > ; 
15+   return  { 
16+     background : {  opacity : ( config . background  as  {  opacity ?: number  } ) ?. opacity  ??  0  } , 
17+   } ; 
18+ } ; 
19+ 
620export  const  WeatherSettings  =  ( )  =>  { 
721  const  {  currentDashboard }  =  useDashboard ( ) ; 
22+   const  savedSettings  =  currentDashboard ?. widgets . find ( 
23+     ( w )  =>  w . id  ===  SETTING_ID 
24+   )  as  WeatherWidgetSettings  |  undefined ; 
825  const  [ settings ,  setSettings ]  =  useState < WeatherWidgetSettings > ( { 
9-     enabled : currentDashboard ?. widgets . find ( w   =>   w . id   ===   'weather' ) ?. enabled  ??  false , 
10-     config : currentDashboard ?. widgets . find ( w   =>   w . id   ===   'weather' ) ?. config   ??   { } , 
26+     enabled : savedSettings ?. enabled  ??  false , 
27+     config : migrateConfig ( savedSettings ?. config ) , 
1128  } ) ; 
1229
1330  if  ( ! currentDashboard )  { 
@@ -20,12 +37,30 @@ export const WeatherSettings = () => {
2037      description = "Configure weather widget display options." 
2138      settings = { settings } 
2239      onSettingsChange = { setSettings } 
23-       widgetId = "weather" 
40+       widgetId = { SETTING_ID } 
2441    > 
25-       { /* Add specific settings controls here */ } 
26-       < div  className = "text-slate-300" > 
27-         Additional settings will appear here
28-       </ div > 
42+       { ( handleConfigChange )  =>  ( 
43+         < div  className = "space-y-4" > 
44+           < div  className = "flex items-center justify-between" > 
45+             < span  className = "text-sm text-slate-300" > Background Opacity</ span > 
46+             < div  className = "flex items-center gap-2" > 
47+               < input 
48+                 type = "range" 
49+                 min = "0" 
50+                 max = "100" 
51+                 value = { settings . config . background . opacity } 
52+                 onChange = { ( e )  => 
53+                   handleConfigChange ( {  background : {  opacity : parseInt ( e . target . value )  }  } ) 
54+                 } 
55+                 className = "w-20 h-2 bg-slate-600 rounded-lg appearance-none cursor-pointer" 
56+               /> 
57+               < span  className = "text-xs text-slate-400 w-8" > 
58+                 { settings . config . background . opacity } %
59+               </ span > 
60+             </ div > 
61+           </ div > 
62+         </ div > 
63+       ) } 
2964    </ BaseSettingsSection > 
3065  ) ; 
3166} ;  
0 commit comments