feat: enhance ChangeAPI and ChangePreferences components; add "API key update" functionality and save preferences feature
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user