fix: increase autoClose duration for Toast notifications to improve user experience
refactor: enhance error handling in fetchWeather function with detailed console messages
This commit is contained in:
@@ -12,7 +12,7 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
|||||||
<Header />
|
<Header />
|
||||||
<ToastContainer
|
<ToastContainer
|
||||||
position="top-right"
|
position="top-right"
|
||||||
autoClose={3000}
|
autoClose={5000}
|
||||||
hideProgressBar={false}
|
hideProgressBar={false}
|
||||||
newestOnTop
|
newestOnTop
|
||||||
closeOnClick
|
closeOnClick
|
||||||
|
@@ -2,7 +2,6 @@ import React from "react";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { fetchWeather } from "../utils/apiFunc";
|
import { fetchWeather } from "../utils/apiFunc";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import IsLoading from "./IsLoading"; // FIX ERRROR
|
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
const WeatherCard: React.FC = () => {
|
const WeatherCard: React.FC = () => {
|
||||||
@@ -20,7 +19,7 @@ const WeatherCard: React.FC = () => {
|
|||||||
toast.promise(fetchWeather(city, getAPIKey()), {
|
toast.promise(fetchWeather(city, getAPIKey()), {
|
||||||
pending: "Fetching weather data...",
|
pending: "Fetching weather data...",
|
||||||
success: "Weather data loaded successfully!",
|
success: "Weather data loaded successfully!",
|
||||||
error: "Error loading weather data!",
|
error: "Error loading weather data! (Check console for details)",
|
||||||
});
|
});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
@@ -42,7 +41,6 @@ const WeatherCard: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
<button type="submit">Get Weather</button>
|
<button type="submit">Get Weather</button>
|
||||||
</form>
|
</form>
|
||||||
{loading && <IsLoading message="Loading weather data..." />}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -4,9 +4,11 @@ export const fetchWeather = async (city: string, apiKey: string) => {
|
|||||||
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw new Error("Network response was not ok");
|
console.error("You are not authorized to access this resource. Please check your API key.");
|
||||||
} else if (response.ok) {
|
} else if (response.ok) {
|
||||||
return response.json();
|
return response.json();
|
||||||
|
} else {
|
||||||
|
console.error("Error fetching location data: ", response.statusText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const lat = location[0].lat;
|
const lat = location[0].lat;
|
||||||
|
@@ -5,7 +5,7 @@ export type ToastType = "success" | "error" | "info" | "warning";
|
|||||||
export const myToast = (message: string, msgType: ToastType) => {
|
export const myToast = (message: string, msgType: ToastType) => {
|
||||||
let config: ToastOptions = {
|
let config: ToastOptions = {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
autoClose: 3000,
|
autoClose: 5000,
|
||||||
hideProgressBar: false,
|
hideProgressBar: false,
|
||||||
closeOnClick: true,
|
closeOnClick: true,
|
||||||
pauseOnHover: true,
|
pauseOnHover: true,
|
||||||
|
Reference in New Issue
Block a user