Skip to content

Commit e78e4fc

Browse files
author
Weronika Wolska
committed
add loading and error handling in dashboard
1 parent 5337a3b commit e78e4fc

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

angular-monorepo/libs/entities/data-repository/src/lib/services/mock-entity.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,13 @@ export class MockEntityService {
178178
}
179179

180180
getLocationStats(): Observable<LocationStats> {
181-
return of({
182-
lastWeekLocationOccupancy: this.lastWeekLocationOccupancy,
183-
lastWeekEmployeesVisits: this.mapVisits(),
184-
});
181+
return defer(() => {
182+
if (Math.random() < 0.1) return throwError(() => 'Failed to update');
183+
return of({
184+
lastWeekLocationOccupancy: this.lastWeekLocationOccupancy,
185+
lastWeekEmployeesVisits: this.mapVisits(),
186+
});
187+
}).pipe(delay(1000));
185188
}
186189

187190
private mapVisits() {
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import { EntityService } from '@angular-monorepo/entities/data-repository';
22
import { Component } from '@angular/core';
3-
3+
import { catchError, of } from 'rxjs';
4+
import { MessageService } from 'primeng/api';
45
@Component({
56
selector: 'angular-monorepo-location-dashboard',
67
templateUrl: './location-dashboard.component.html',
78
styleUrls: ['./location-dashboard.component.scss'],
89
})
910
export class LocationDashboardComponent {
10-
data$ = this.entityService.getLocationStats();
11+
data$ = this.entityService.getLocationStats().pipe(
12+
catchError(() => {
13+
this.messageService.add({
14+
severity: 'error',
15+
detail: 'Could not load location data',
16+
});
17+
return of({
18+
lastWeekLocationOccupancy: [],
19+
lastWeekEmployeesVisits: [],
20+
});
21+
})
22+
);
1123

12-
constructor(private entityService: EntityService) {}
24+
constructor(
25+
private entityService: EntityService,
26+
private messageService: MessageService
27+
) {}
1328
}

0 commit comments

Comments
 (0)