Styling publications on home page.

This commit is contained in:
Florian THIERRY
2024-06-04 13:55:26 +02:00
parent 58295398e0
commit d3041cf03d
9 changed files with 154 additions and 7 deletions

View File

@@ -0,0 +1,34 @@
import { Injectable, inject } from "@angular/core";
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
import { BehaviorSubject, Observable } from "rxjs";
import { MatSnackBar } from "@angular/material/snack-bar"
import { Publication } from "../../core/rest-services/publications/model/publication";
@Injectable()
export class HomeService {
private publicationRestService = inject(PublicationRestService);
private snackBar = inject(MatSnackBar);
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
private isLoadingSubject = new BehaviorSubject<boolean>(false);
get isLoading$(): Observable<boolean> {
return this.isLoadingSubject.asObservable();
}
get publications$(): Observable<Publication[]> {
return this.publicationsSubject.asObservable();
}
startLatestPublicationsRetrieving(): void {
this.isLoadingSubject.next(true);
this.publicationRestService.getLatest()
.then(publications => this.publicationsSubject.next(publications))
.catch(error => {
this.snackBar.open('An error occurred while retrieving latest publications...');
console.error('An error occurred while retrieving latest publications...', error);
})
.finally(() => this.isLoadingSubject.next(false));
}
}