Added weather data component to display weather data - also added function to display data

This commit is contained in:
2025-07-31 15:58:38 +02:00
parent 08b6807b96
commit 480b5188ba
3 changed files with 45 additions and 11 deletions

View File

@@ -4,7 +4,9 @@ export const fetchWeather = async (city: string, apiKey: string) => {
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
).then((response) => {
if (response.status === 401) {
console.error("You are not authorized to access this resource. Please check your API key.");
console.error(
"You are not authorized to access this resource. Please check your API key."
);
} else if (response.ok) {
return response.json();
} else {
@@ -18,5 +20,5 @@ export const fetchWeather = async (city: string, apiKey: string) => {
const weather = await fetch(
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}`
).then((response) => response.json());
console.log(weather);
localStorage.setItem("weather", JSON.stringify(weather));
};