location getting passed as prop now

This commit is contained in:
christian 2024-05-04 20:30:04 +02:00
parent 910e61e51c
commit c33c7568d1

View File

@ -54,23 +54,27 @@ interface LocationType {
latitude: string; latitude: string;
longtitude: string; longtitude: string;
} }
const kelvin = 273.15;
async function getForecast(location: LocationType): Promise<Forecast> { async function getForecast(location: LocationType): Promise<Forecast> {
const {latitude, longtitude} = location; const {latitude, longtitude} = location;
const appId = '546911d860cb81f16585f7973b394b70'; const appId = '546911d860cb81f16585f7973b394b70';
const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longtitude}&appid=${appId}`) const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longtitude}&appid=${appId}`)
if (!res.ok){ if (!res.ok) {
throw new Error(`This is not great ${error}`); throw new Error(`This is not great ${error}`);
} }
return res.json(); return res.json();
} }
export default async function Weather(location: LocationType) { export default async function Weather(props: {location: LocationType}) {
const location = props.location
const weather = await getForecast(location) const weather = await getForecast(location)
const temp = weather.main.temp - kelvin
return ( return (
<main> <main>
<h1>Forecast</h1> <h1>Forecast</h1>
<p>{weather.name}</p> <p>{temp}</p>
<p></p>
</main> </main>
); );
} }