Pages/shows: show toasts when loading
This commit is contained in:
parent
7ee8e7e3ed
commit
68c7c8e1b8
1 changed files with 10 additions and 1 deletions
|
|
@ -2,6 +2,8 @@ import {Component, inject} from '@angular/core';
|
|||
import {ShowsApiService} from '../../services/shows/shows-api.service';
|
||||
import {Show} from '../../interfaces/show';
|
||||
import {ShowsApiResponse} from '../../interfaces/shows-api-response';
|
||||
import {Toast} from '../../interfaces/toast';
|
||||
import {ToastService} from '../../services/toast/toast.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shows',
|
||||
|
|
@ -11,17 +13,24 @@ import {ShowsApiResponse} from '../../interfaces/shows-api-response';
|
|||
})
|
||||
export class ShowsComponent {
|
||||
private api: ShowsApiService = inject(ShowsApiService);
|
||||
private toastService: ToastService = inject(ToastService);
|
||||
|
||||
shows: Show[] = [];
|
||||
|
||||
constructor() {
|
||||
let loadToast: Toast = {body: "Loading shows..."};
|
||||
this.toastService.show(loadToast);
|
||||
this.api.getShows().subscribe({
|
||||
next: (response: ShowsApiResponse) => {
|
||||
this.shows = response.shows;
|
||||
}, error: (err: any) => {
|
||||
console.error("Error: ", err);
|
||||
}, complete: () => {
|
||||
console.log("Loaded shows")
|
||||
let successToast: Toast = {
|
||||
body: "Shows have been loaded!",
|
||||
htmlClass: "bg-success text-light"
|
||||
}
|
||||
this.toastService.show(successToast);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue