45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
import { Observable, Subscription } from 'rxjs';
|
|
import { PublicationListComponent } from '../../components/publication-list/publication-list.component';
|
|
import { Publication } from '../../core/rest-services/publications/model/publication';
|
|
import { HomeService } from './home.service';
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
@Component({
|
|
selector: 'app-home',
|
|
standalone: true,
|
|
imports: [
|
|
CommonModule,
|
|
MatProgressSpinnerModule,
|
|
PublicationListComponent
|
|
],
|
|
templateUrl: './home.component.html',
|
|
styleUrl: './home.component.scss',
|
|
providers: [HomeService]
|
|
})
|
|
export class HomeComponent implements OnInit, OnDestroy {
|
|
private homeService = inject(HomeService);
|
|
private isLoadingSubscription?: Subscription;
|
|
private publicationsSubscription?: Subscription;
|
|
isLoading = signal(false);
|
|
publicationsIsEmpty = signal(true);
|
|
|
|
get publications$(): Observable<Publication[]> {
|
|
return this.homeService.publications$;
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.isLoadingSubscription = this.homeService.isLoading$
|
|
.subscribe(isLoading => this.isLoading.set(isLoading));
|
|
this.publicationsSubscription = this.homeService.publications$
|
|
.subscribe(publications => this.publicationsIsEmpty.set(publications.length > 0));
|
|
this.homeService.startLatestPublicationsRetrieving();
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
this.isLoadingSubscription?.unsubscribe();
|
|
this.publicationsSubscription?.unsubscribe();
|
|
}
|
|
}
|