mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
refactor(app): share application components and request services
This commit is contained in:
1 parent
a0a0128a59
commit
a67bc60a29
84 files changed
+2798
-1731
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { applicationServices } from './services/application.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { deriveWeatherEffectProfile, weatherAltitudeFactors } from './weatherEffectsMath.js';
|
||||
|
||||
@@ -368,14 +369,10 @@ export class CockpitCloudEffectsController {
|
||||
|
||||
this.abort?.abort();
|
||||
this.abort = new AbortController();
|
||||
const params = new URLSearchParams({
|
||||
latitude: point.latitude.toFixed(5),
|
||||
longitude: point.longitude.toFixed(5),
|
||||
});
|
||||
this.pending = fetch(`/api/weather-effects?${params}`, { signal: this.abort.signal })
|
||||
.then(async (response) => {
|
||||
if (!response.ok) throw new Error(`Cloud weather unavailable (${response.status})`);
|
||||
const payload = await response.json();
|
||||
const pending = applicationServices.weather.getConditions(point.latitude, point.longitude, { signal: this.abort.signal });
|
||||
const request = this.abort;
|
||||
this.pending = pending.then(async (payload) => {
|
||||
if (this.abort !== request || request.signal.aborted) return null;
|
||||
if (!payload?.weather) throw new Error('Cloud weather observation unavailable');
|
||||
this.weather = payload.weather;
|
||||
this.fetchedAt = Date.now();
|
||||
@@ -385,6 +382,7 @@ export class CockpitCloudEffectsController {
|
||||
return payload.weather;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (request.signal.aborted || this.abort !== request) return;
|
||||
if (error?.name !== 'AbortError') {
|
||||
this.targetStrength = 0;
|
||||
this.canvas.dataset.sourceStatus = 'unavailable';
|
||||
@@ -392,8 +390,7 @@ export class CockpitCloudEffectsController {
|
||||
return null;
|
||||
})
|
||||
.finally(() => {
|
||||
this.pending = null;
|
||||
this.abort = null;
|
||||
if (this.abort === request) { this.pending = null; this.abort = null; }
|
||||
});
|
||||
return this.pending;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user