diff --git a/src/features/weather/Weather.jsx b/src/features/weather/Weather.jsx index d072fac5..8f0dfa62 100644 --- a/src/features/weather/Weather.jsx +++ b/src/features/weather/Weather.jsx @@ -17,16 +17,23 @@ const WeatherWidget = memo(() => { const [weatherData, setWeatherData] = useState({}); const updateWeather = useCallback(async () => { - const data = await getWeather(location, done); - setWeatherData(data); - setDone(data.done); + const data = await getWeather(location); + console.log('Weather data received:', data); + if (data) { + setWeatherData(data); + setDone(data.done); + } else { + // Fallback if data is undefined + setWeatherData({ done: true }); + setDone(true); + } const zoomWeather = `${Number((localStorage.getItem('zoomWeather') || 100) / 100)}em`; const weatherElement = document.querySelector('.weather'); if (weatherElement) { weatherElement.style.fontSize = zoomWeather; } - }, [location, done]); + }, [location]); useEffect(() => { const handleRefresh = async (data) => { diff --git a/src/features/weather/api/getWeather.js b/src/features/weather/api/getWeather.js index 3f68a7f8..ae0e67c8 100644 --- a/src/features/weather/api/getWeather.js +++ b/src/features/weather/api/getWeather.js @@ -9,11 +9,7 @@ const convertTemperature = (temp, format) => { return Math.round(temp); }; -export const getWeather = async (location, done) => { - if (done === true) { - return; - } - +export const getWeather = async (location) => { let cached = localStorage.getItem('currentWeather'); if (cached) { cached = JSON.parse(cached); @@ -24,15 +20,15 @@ export const getWeather = async (location, done) => { } try { - const response = await fetch( - variables.constants.API_URL + `/weather?city=${location}&language=${variables.languagecode}`, - ); + const response = await fetch(variables.constants.API_URL + `/weather?city=${location}`); if (!response.ok) { - throw new Error('Network response was not ok'); + console.error('Weather API response not ok:', response.status, response.statusText); + throw new Error(`Network response was not ok: ${response.status}`); } const data = await response.json(); + console.log('Weather API response:', data); if (data.status === 404) { return { @@ -75,5 +71,9 @@ export const getWeather = async (location, done) => { return cacheable; } catch (error) { console.error('Fetch Error: ', error); + return { + location: variables.getMessage('widgets.weather.fetch_error'), + done: true, + }; } };