fix hourly graph not updating close #77

This commit is contained in:
Matt Walsh
2025-05-02 23:22:00 -05:00
parent 91f669e828
commit eacd82b4f4
3 changed files with 17 additions and 5 deletions

View File

@@ -130,6 +130,8 @@ class CurrentWeather extends WeatherDisplay {
// make data available outside this class // make data available outside this class
// promise allows for data to be requested before it is available // promise allows for data to be requested before it is available
async getCurrentWeather(stillWaiting) { async getCurrentWeather(stillWaiting) {
// an external caller has requested data, set up auto reload
this.setAutoReload();
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting); if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
return new Promise((resolve) => { return new Promise((resolve) => {
if (this.data) resolve(this.data); if (this.data) resolve(this.data);

View File

@@ -139,6 +139,8 @@ class Hourly extends WeatherDisplay {
// promise allows for data to be requested before it is available // promise allows for data to be requested before it is available
async getCurrentData(stillWaiting) { async getCurrentData(stillWaiting) {
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting); if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
// an external caller has requested data, set up auto reload
this.setAutoReload();
return new Promise((resolve) => { return new Promise((resolve) => {
if (this.data) resolve(this.data); if (this.data) resolve(this.data);
// data not available, put it into the data callback queue // data not available, put it into the data callback queue

View File

@@ -134,10 +134,9 @@ class WeatherDisplay {
// refresh doesn't delete existing data, and is reused if the silent refresh fails // refresh doesn't delete existing data, and is reused if the silent refresh fails
if (!refresh) { if (!refresh) {
this.data = undefined; this.data = undefined;
// clear any refresh timers
this.clearAutoReload();
} }
// clear any refresh timers
clearTimeout(this.autoRefreshHandle);
this.autoRefreshHandle = null;
// store weatherParameters locally in case we need them later // store weatherParameters locally in case we need them later
if (weatherParameters) this.weatherParameters = weatherParameters; if (weatherParameters) this.weatherParameters = weatherParameters;
@@ -150,8 +149,8 @@ class WeatherDisplay {
return false; return false;
} }
// set up auto reload // set up auto reload if necessary
this.autoRefreshHandle = setTimeout(() => this.getData(false, true), settings.refreshTime.value); this.setAutoReload();
// recalculate navigation timing (in case it was modified in the constructor) // recalculate navigation timing (in case it was modified in the constructor)
this.calcNavTiming(); this.calcNavTiming();
@@ -435,6 +434,15 @@ class WeatherDisplay {
this.stillWaitingCallbacks.forEach((callback) => callback()); this.stillWaitingCallbacks.forEach((callback) => callback());
this.stillWaitingCallbacks = []; this.stillWaitingCallbacks = [];
} }
clearAutoReload() {
clearInterval(this.autoRefreshHandle);
this.autoRefreshHandle = null;
}
setAutoReload() {
this.autoRefreshHandle = this.autoRefreshHandle ?? setInterval(() => this.getData(false, true), settings.refreshTime.value);
}
} }
export default WeatherDisplay; export default WeatherDisplay;