fix(weather0: issue with dependency

This commit is contained in:
alexsparkes
2026-01-24 00:40:10 +00:00
parent e43615bcdf
commit 92bddd0538
2 changed files with 20 additions and 13 deletions

View File

@@ -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) => {

View File

@@ -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,
};
}
};