Skip to content

Commit 8fa00b3

Browse files
committed
hourly and travel forecast silent reload
1 parent 23cc1a1 commit 8fa00b3

13 files changed

+54
-48
lines changed

server/scripts/modules/currentweather.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CurrentWeather extends WeatherDisplay {
2323

2424
async getData(_weatherParameters, refresh) {
2525
// always load the data for use in the lower scroll
26-
const superResult = super.getData(_weatherParameters);
26+
const superResult = super.getData(_weatherParameters, refresh);
2727
const weatherParameters = _weatherParameters ?? this.weatherParameters;
2828

2929
// filter for 4-letter observation stations, only those contain sky conditions and thus an icon

server/scripts/modules/extendedforecast.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ExtendedForecast extends WeatherDisplay {
1919
}
2020

2121
async getData(_weatherParameters, refresh) {
22-
if (!super.getData(_weatherParameters)) return;
22+
if (!super.getData(_weatherParameters, refresh)) return;
2323
const weatherParameters = _weatherParameters ?? this.weatherParameters;
2424

2525
// request us or si units

server/scripts/modules/hazards.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Hazards extends WeatherDisplay {
2828

2929
async getData(weatherParameters, refresh) {
3030
// super checks for enabled
31-
const superResult = super.getData(weatherParameters);
31+
const superResult = super.getData(weatherParameters, refresh);
3232

3333
const alert = this.checkbox.querySelector('.alert');
3434
alert.classList.remove('show');

server/scripts/modules/hourly-graph.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HourlyGraph extends WeatherDisplay {
2424
}
2525

2626
async getData(_weatherParameters, refresh) {
27-
if (!super.getData()) return;
27+
if (!super.getData(undefined, refresh)) return;
2828

2929
const data = await getHourlyData(() => this.stillWaiting());
3030
if (data === undefined) {

server/scripts/modules/hourly.mjs

+14-7
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,28 @@ class Hourly extends WeatherDisplay {
2929

3030
async getData(weatherParameters, refresh) {
3131
// super checks for enabled
32-
const superResponse = super.getData(weatherParameters);
32+
const superResponse = super.getData(weatherParameters, refresh);
3333
let forecast;
3434
try {
3535
// get the forecast
36-
forecast = await json(weatherParameters.forecastGridData, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
36+
forecast = await json(this.weatherParameters.forecastGridData, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
37+
// parse the forecast
38+
this.data = await parseForecast(forecast.properties);
3739
} catch (error) {
3840
console.error('Get hourly forecast failed');
3941
console.error(error.status, error.responseJSON);
40-
if (this.isEnabled) this.setStatus(STATUS.failed);
41-
// return undefined to other subscribers
42-
this.getDataCallback(undefined);
43-
return;
42+
// use old data if available
43+
if (this.data) {
44+
console.log('Using previous hourly forecast');
45+
// don't return, this.data is usable from the previous update
46+
} else {
47+
if (this.isEnabled) this.setStatus(STATUS.failed);
48+
// return undefined to other subscribers
49+
this.getDataCallback(undefined);
50+
return;
51+
}
4452
}
4553

46-
this.data = await parseForecast(forecast.properties);
4754
this.getDataCallback();
4855
if (!superResponse) return;
4956

server/scripts/modules/latestobservations.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LatestObservations extends WeatherDisplay {
1717
}
1818

1919
async getData(_weatherParameters, refresh) {
20-
if (!super.getData(_weatherParameters)) return;
20+
if (!super.getData(_weatherParameters, refresh)) return;
2121
const weatherParameters = _weatherParameters ?? this.weatherParameters;
2222

2323
// calculate distance to each station

server/scripts/modules/localforecast.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LocalForecast extends WeatherDisplay {
1515
}
1616

1717
async getData(_weatherParameters, refresh) {
18-
if (!super.getData(_weatherParameters)) return;
18+
if (!super.getData(_weatherParameters, refresh)) return;
1919
const weatherParameters = _weatherParameters ?? this.weatherParameters;
2020

2121
// get raw data

server/scripts/modules/radar.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Radar extends WeatherDisplay {
4343
}
4444

4545
async getData(_weatherParameters, refresh) {
46-
if (!super.getData(_weatherParameters)) return;
46+
if (!super.getData(_weatherParameters, refresh)) return;
4747
const weatherParameters = _weatherParameters ?? this.weatherParameters;
4848

4949
// ALASKA AND HAWAII AREN'T SUPPORTED!

server/scripts/modules/regionalforecast.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RegionalForecast extends WeatherDisplay {
2222
}
2323

2424
async getData(_weatherParameters, refresh) {
25-
if (!super.getData(_weatherParameters)) return;
25+
if (!super.getData(_weatherParameters, refresh)) return;
2626
const weatherParameters = _weatherParameters ?? this.weatherParameters;
2727

2828
// pre-load the base map

server/scripts/modules/travelforecast.mjs

+29-7
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,42 @@ class TravelForecast extends WeatherDisplay {
2626
if (extra !== 0) this.timing.delay.push(Math.round(this.extra * this.cityHeight));
2727
// add the final 3 second delay
2828
this.timing.delay.push(150);
29+
30+
// add previous data cache
31+
this.previousData = [];
2932
}
3033

3134
async getData(weatherParameters, refresh) {
3235
// super checks for enabled
33-
if (!super.getData(this.weatherParameters)) return;
34-
const forecastPromises = TravelCities.map(async (city) => {
36+
if (!super.getData(weatherParameters, refresh)) return;
37+
38+
// clear stored data if not refresh
39+
if (!refresh) {
40+
this.previousData = [];
41+
}
42+
43+
const forecastPromises = TravelCities.map(async (city, index) => {
3544
try {
3645
// get point then forecast
3746
if (!city.point) throw new Error('No pre-loaded point');
38-
const forecast = await json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/forecast`, {
39-
data: {
40-
units: settings.units.value,
41-
},
42-
});
47+
let forecast;
48+
try {
49+
forecast = await json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/forecast`, {
50+
data: {
51+
units: settings.units.value,
52+
},
53+
});
54+
// store for the next run
55+
this.previousData[index] = forecast;
56+
} catch (e) {
57+
// if there's previous data use it
58+
if (this.previousData?.[index]) {
59+
forecast = this.previousData?.[index];
60+
} else {
61+
// otherwise re-throw for the standard error handling
62+
throw (e);
63+
}
64+
}
4365
// determine today or tomorrow (shift periods by 1 if tomorrow)
4466
const todayShift = forecast.properties.periods[0].isDaytime ? 0 : 1;
4567
// return a pared-down forecast

server/styles/main.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/styles/main.css.map

+1-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

views/index.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
<div id="divTwcBottomRight">
134134
<div id="ToggleMedia">
135135
<img class="navButton off" src="images/nav/ic_volume_off_white_24dp_2x.png" title="Unmute" />
136-
<img class="navButton on" src="images/nav/ic_volume_on_white_24dp_2x.png" title="Unmute" />
136+
<img class="navButton on" src="images/nav/ic_volume_on_white_24dp_2x.png" title="Mute" />
137137
</div>
138138
<img id="ToggleFullScreen" class="navButton" src="images/nav/ic_fullscreen_white_24dp_2x.png" title="Enter Fullscreen" />
139139
</div>

0 commit comments

Comments
 (0)