Skip to content

Commit 341aae4

Browse files
committed
Merge branch 'pr/830'
2 parents 7c4aa68 + 7f62907 commit 341aae4

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/app/api/weather/route.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
export const POST = async (req: Request) => {
22
try {
3-
const body: { lat: number; lng: number; temperatureUnit: 'C' | 'F' } =
4-
await req.json();
3+
const body: {
4+
lat: number;
5+
lng: number;
6+
measureUnit: 'Imperial' | 'Metric';
7+
} = await req.json();
58

69
if (!body.lat || !body.lng) {
710
return Response.json(
@@ -13,7 +16,9 @@ export const POST = async (req: Request) => {
1316
}
1417

1518
const res = await fetch(
16-
`https://api.open-meteo.com/v1/forecast?latitude=${body.lat}&longitude=${body.lng}&current=weather_code,temperature_2m,is_day,relative_humidity_2m,wind_speed_10m&timezone=auto${body.temperatureUnit === 'C' ? '' : '&temperature_unit=fahrenheit'}`,
19+
`https://api.open-meteo.com/v1/forecast?latitude=${body.lat}&longitude=${body.lng}&current=weather_code,temperature_2m,is_day,relative_humidity_2m,wind_speed_10m&timezone=auto${
20+
body.measureUnit === 'Metric' ? '' : '&temperature_unit=fahrenheit'
21+
}${body.measureUnit === 'Metric' ? '' : '&wind_speed_unit=mph'}`,
1722
);
1823

1924
const data = await res.json();
@@ -35,13 +40,15 @@ export const POST = async (req: Request) => {
3540
windSpeed: number;
3641
icon: string;
3742
temperatureUnit: 'C' | 'F';
43+
windSpeedUnit: 'm/s' | 'mph';
3844
} = {
3945
temperature: data.current.temperature_2m,
4046
condition: '',
4147
humidity: data.current.relative_humidity_2m,
4248
windSpeed: data.current.wind_speed_10m,
4349
icon: '',
44-
temperatureUnit: body.temperatureUnit,
50+
temperatureUnit: body.measureUnit === 'Metric' ? 'C' : 'F',
51+
windSpeedUnit: body.measureUnit === 'Metric' ? 'm/s' : 'mph',
4552
};
4653

4754
const code = data.current.weather_code;

src/app/settings/page.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ const Page = () => {
148148
const [automaticImageSearch, setAutomaticImageSearch] = useState(false);
149149
const [automaticVideoSearch, setAutomaticVideoSearch] = useState(false);
150150
const [systemInstructions, setSystemInstructions] = useState<string>('');
151-
const [temperatureUnit, setTemperatureUnit] = useState<'C' | 'F'>('C');
151+
const [measureUnit, setMeasureUnit] = useState<'Imperial' | 'Metric'>(
152+
'Metric',
153+
);
152154
const [savingStates, setSavingStates] = useState<Record<string, boolean>>({});
153155

154156
useEffect(() => {
@@ -211,7 +213,9 @@ const Page = () => {
211213

212214
setSystemInstructions(localStorage.getItem('systemInstructions')!);
213215

214-
setTemperatureUnit(localStorage.getItem('temperatureUnit')! as 'C' | 'F');
216+
setMeasureUnit(
217+
localStorage.getItem('measureUnit')! as 'Imperial' | 'Metric',
218+
);
215219

216220
setIsLoading(false);
217221
};
@@ -371,8 +375,8 @@ const Page = () => {
371375
localStorage.setItem('embeddingModel', value);
372376
} else if (key === 'systemInstructions') {
373377
localStorage.setItem('systemInstructions', value);
374-
} else if (key === 'temperatureUnit') {
375-
localStorage.setItem('temperatureUnit', value.toString());
378+
} else if (key === 'measureUnit') {
379+
localStorage.setItem('measureUnit', value.toString());
376380
}
377381
} catch (err) {
378382
console.error('Failed to save:', err);
@@ -430,22 +434,22 @@ const Page = () => {
430434
</div>
431435
<div className="flex flex-col space-y-1">
432436
<p className="text-black/70 dark:text-white/70 text-sm">
433-
Temperature Unit
437+
Measurement Units
434438
</p>
435439
<Select
436-
value={temperatureUnit ?? undefined}
440+
value={measureUnit ?? undefined}
437441
onChange={(e) => {
438-
setTemperatureUnit(e.target.value as 'C' | 'F');
439-
saveConfig('temperatureUnit', e.target.value);
442+
setMeasureUnit(e.target.value as 'Imperial' | 'Metric');
443+
saveConfig('measureUnit', e.target.value);
440444
}}
441445
options={[
442446
{
443-
label: 'Celsius',
444-
value: 'C',
447+
label: 'Metric',
448+
value: 'Metric',
445449
},
446450
{
447-
label: 'Fahrenheit',
448-
value: 'F',
451+
label: 'Imperial',
452+
value: 'Imperial',
449453
},
450454
]}
451455
/>

src/components/WeatherWidget.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const WeatherWidget = () => {
1010
windSpeed: 0,
1111
icon: '',
1212
temperatureUnit: 'C',
13+
windSpeedUnit: 'm/s',
1314
});
1415

1516
const [loading, setLoading] = useState(true);
@@ -75,7 +76,7 @@ const WeatherWidget = () => {
7576
body: JSON.stringify({
7677
lat: location.latitude,
7778
lng: location.longitude,
78-
temperatureUnit: localStorage.getItem('temperatureUnit') ?? 'C',
79+
measureUnit: localStorage.getItem('measureUnit') ?? 'Metric',
7980
}),
8081
});
8182

@@ -95,6 +96,7 @@ const WeatherWidget = () => {
9596
windSpeed: data.windSpeed,
9697
icon: data.icon,
9798
temperatureUnit: data.temperatureUnit,
99+
windSpeedUnit: data.windSpeedUnit,
98100
});
99101
setLoading(false);
100102
});
@@ -139,7 +141,7 @@ const WeatherWidget = () => {
139141
</span>
140142
<span className="flex items-center text-xs text-black/60 dark:text-white/60">
141143
<Wind className="w-3 h-3 mr-1" />
142-
{data.windSpeed} km/h
144+
{data.windSpeed} {data.windSpeedUnit}
143145
</span>
144146
</div>
145147
<span className="text-xs text-black/60 dark:text-white/60 mt-1">

0 commit comments

Comments
 (0)