fix spc changing locations close #80

This commit is contained in:
Matt Walsh
2025-05-16 09:39:48 -05:00
parent 317883fc04
commit e89dc52541

View File

@@ -54,23 +54,25 @@ class SpcOutlook extends WeatherDisplay {
async getData(weatherParameters, refresh) { async getData(weatherParameters, refresh) {
if (!super.getData(weatherParameters, refresh)) return; if (!super.getData(weatherParameters, refresh)) return;
let initialData; // initial data does not need to be reloaded on a location change, only during silent refresh
try { if (!this.initialData || refresh) {
// get the three categorical files to get started try {
const filePromises = await Promise.allSettled(this.files.map((file) => json(file))); // get the three categorical files to get started
// store the data, promise will always be fulfilled const filePromises = await Promise.allSettled(this.files.map((file) => json(file)));
initialData = filePromises.map((outlookDay) => outlookDay.value); // store the data, promise will always be fulfilled
} catch (error) { this.initialData = filePromises.map((outlookDay) => outlookDay.value);
console.error('Unable to get spc outlook'); } catch (error) {
console.error(error.status, error.responseJSON); console.error('Unable to get spc outlook');
// if there's no previous data, fail console.error(error.status, error.responseJSON);
if (!this.data) { // if there's no previous data, fail
this.setStatus(STATUS.failed); if (!this.initialData) {
return; this.setStatus(STATUS.failed);
return;
}
} }
} }
// do the initial parsing of the data // do the initial parsing of the data
this.data = testAllPoints([weatherParameters.longitude, weatherParameters.latitude], initialData); this.data = testAllPoints([weatherParameters.longitude, weatherParameters.latitude], this.initialData);
// if all the data returns false the there's nothing to do, skip this screen // if all the data returns false the there's nothing to do, skip this screen
if (this.data.reduce((prev, cur) => prev || !!cur, false)) { if (this.data.reduce((prev, cur) => prev || !!cur, false)) {