mirror of
https://github.com/mue/mue.git
synced 2026-07-16 05:23:49 +02:00
fix(weather0: issue with dependency
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user