v0.2.1! Adds instant Hazard List updates after hazard sync
Some checks are pending
build-docker / Build Image (push) Waiting to run
Some checks are pending
build-docker / Build Image (push) Waiting to run
This commit is contained in:
parent
0f2d64b908
commit
dbb32fd2f9
9 changed files with 362 additions and 5 deletions
|
|
@ -8,11 +8,17 @@ class HazardList extends WeatherDisplay {
|
|||
constructor(navId, elemId) {
|
||||
super(navId, elemId, 'Hazard List', true);
|
||||
this.history = [];
|
||||
this.handleHazardHistoryUpdated = this.handleHazardHistoryUpdated.bind(this);
|
||||
window.addEventListener('hazard-history-updated', this.handleHazardHistoryUpdated);
|
||||
}
|
||||
|
||||
async getData(weatherParameters, refresh) {
|
||||
const superResult = super.getData(weatherParameters, refresh);
|
||||
await this.refreshHistoryNow();
|
||||
return superResult;
|
||||
}
|
||||
|
||||
async refreshHistoryNow() {
|
||||
try {
|
||||
// Fetch hazard history from backend
|
||||
const response = await fetch(withBasePath('api/hazard-history'));
|
||||
|
|
@ -37,8 +43,13 @@ class HazardList extends WeatherDisplay {
|
|||
this.setStatus(STATUS.failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return superResult;
|
||||
async handleHazardHistoryUpdated() {
|
||||
await this.refreshHistoryNow();
|
||||
if (this.active) {
|
||||
this.drawCanvas();
|
||||
}
|
||||
}
|
||||
|
||||
async drawCanvas() {
|
||||
|
|
|
|||
|
|
@ -290,13 +290,19 @@ class Hazards extends WeatherDisplay {
|
|||
}));
|
||||
|
||||
// Send to backend
|
||||
await fetch(withBasePath('api/hazard-history'), {
|
||||
const response = await fetch(withBasePath('api/hazard-history'), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ location, locationKey, hazards }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Hazard history sync failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
window.dispatchEvent(new CustomEvent('hazard-history-updated'));
|
||||
} catch (error) {
|
||||
// Silently fail - hazard history is non-critical
|
||||
if (debugFlag('verbose-failures')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue