Skip to content

Commit 3a994e2

Browse files
committed
update weather to include background opacity
1 parent 969434a commit 3a994e2

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

src/frontend/components/Settings/sections/StandingsSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const migrateConfig = (savedConfig: unknown): StandingsWidgetSettings['config']
2828
delta: { enabled: (config.delta as { enabled?: boolean })?.enabled ?? true },
2929
lastTime: { enabled: (config.lastTime as { enabled?: boolean })?.enabled ?? true },
3030
fastestTime: { enabled: (config.fastestTime as { enabled?: boolean })?.enabled ?? true },
31-
background: { opacity: (config.background as { opacity?: number })?.opacity ?? 25 },
31+
background: { opacity: (config.background as { opacity?: number })?.opacity ?? 0 },
3232
};
3333
};
3434

src/frontend/components/Settings/sections/WeatherSettings.tsx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@ import { BaseSettingsSection } from '../components/BaseSettingsSection';
33
import { WeatherWidgetSettings } from '../types';
44
import { 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+
620
export 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
};

src/frontend/components/Settings/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export interface RelativeWidgetSettings extends BaseWidgetSettings {
2525
}
2626

2727
export interface WeatherWidgetSettings extends BaseWidgetSettings {
28-
// Add specific weather settings here
28+
config: {
29+
background: { opacity: number };
30+
};
2931
}
3032

3133
export interface TrackMapWidgetSettings extends BaseWidgetSettings {

src/frontend/components/Weather/Weather.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { WeatherTrackWetness } from './WeatherTrackWetness/WeatherTrackWetness';
66
import { WeatherTrackRubbered } from './WeatherTrackRubbered/WeatherTrackRubbered';
77
import { WindDirection } from './WindDirection/WindDirection';
88
import { useTrackRubberedState } from './hooks/useTrackRubberedState';
9+
import { useWeatherSettings } from './hooks/useWeatherSettings';
910

1011
export const Weather = () => {
1112
const [parent] = useAutoAnimate();
@@ -14,10 +15,14 @@ export const Weather = () => {
1415
const windSpeed = weather.windVelocity;
1516
const relativeWindDirection = (weather.windDirection ?? 0) - (weather.windYaw ?? 0);
1617
const trackRubbered = useTrackRubberedState();
18+
const settings = useWeatherSettings();
1719

1820
return (
1921
<div
20-
className="w-full inline-flex flex-row bg-slate-800/25 rounded-sm"
22+
className="w-full inline-flex flex-row bg-slate-800/[var(--bg-opacity)] rounded-sm"
23+
style={{
24+
['--bg-opacity' as string]: `${settings?.background?.opacity ?? 25}%`,
25+
}}
2126
ref={parent}
2227
>
2328
<div className="flex flex-col p-2 w-full rounded-sm gap-2">
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useDashboard } from '@irdashies/context';
2+
import { WeatherWidgetSettings } from '../../Settings/types';
3+
4+
export const useWeatherSettings = () => {
5+
const { currentDashboard } = useDashboard();
6+
7+
const weatherSettings = currentDashboard?.widgets.find(
8+
(widget) => widget.id === 'weather',
9+
)?.config;
10+
11+
return weatherSettings as WeatherWidgetSettings['config'];
12+
};

0 commit comments

Comments
 (0)