'Sometimes API is taking too long to load
@action('Get District')
async getDistrict(districtId: number, current = false): Promise<IDistrictInfo> {
this._adminStore.adminDistrictDetailsStore.setLoading(true);
try {
let district;
if (current) {
district = await this._http.get<IDistrictInfo>(`${environment.urls.api}/districts/${districtId}/current`).toPromise();
} else {
district = await this._http.get<IDistrictInfo>(`${environment.urls.api}/districts/${districtId}`).toPromise();
}
console.log("district", district, current)
await this.getSchools(districtId);
await this.getDistrictPendingCovidData(districtId);
applyTransaction(() => {
this._adminStore.adminDistrictDetailsStore.setError(null);
this._adminStore.adminDistrictDetailsStore.setLoading(false);
this._adminStore.adminDistrictDetailsStore.update({ district });
});
return district;
} catch (e) {
console.error(e);
applyTransaction(() => {
this._adminStore.adminDistrictDetailsStore.setError(e.message);
this._adminStore.adminDistrictDetailsStore.setLoading(false);
});
return null;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
