This repository has been archived on 2026-05-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Codiki/frontend/src/app/pages/home/home.service.ts
T

34 lines
1.4 KiB
TypeScript

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));
}
}