feat: enhance ChangeAPI and ChangePreferences components; add "API key update" functionality and save preferences feature

This commit is contained in:
2025-08-01 01:06:58 +02:00
parent 6f3d945213
commit 8341e50dc8
7 changed files with 250 additions and 41 deletions

View File

@@ -1,22 +1,20 @@
export type units = "metric" | "imperial";
import { myToast } from "./toastify";
export const fetchWeather = async (
city: string,
apiKey: string,
units: units
units: string
) => {
// Get location data
const location = await fetch(
`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."
);
myToast("You are not authorized to access this resource. Please check your API key.", "error");
} else if (response.ok) {
return response.json();
} else {
console.error("Error fetching location data: ", response.statusText);
myToast("Error fetching location data: " + response.statusText, "error");
}
});
const lat = location[0].lat;