Styling publications on home page.
This commit is contained in:
34
frontend/src/app/pages/home/home.service.ts
Normal file
34
frontend/src/app/pages/home/home.service.ts
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user