44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import {Component, inject, signal} from '@angular/core';
|
|
import {IonicModule, LoadingController, ToastController} from "@ionic/angular";
|
|
import {GetPostDto, PostsService} from "../../services/api";
|
|
import {firstValueFrom} from "rxjs";
|
|
import {PostComponent} from "../../components/post/post.component";
|
|
|
|
@Component({
|
|
selector: 'app-publication',
|
|
templateUrl: './publication.component.html',
|
|
styleUrls: ['./publication.component.scss'],
|
|
imports: [
|
|
IonicModule,
|
|
PostComponent
|
|
]
|
|
})
|
|
export class PublicationComponent {
|
|
private postsService = inject(PostsService);
|
|
private loadCtrl = inject(LoadingController);
|
|
private toastCtrl = inject(ToastController);
|
|
|
|
posts = signal<GetPostDto[]>([]);
|
|
|
|
async ionViewWillEnter() {
|
|
const loading = await this.loadCtrl.create({
|
|
message: 'Chargement...',
|
|
spinner: 'lines-sharp-small'
|
|
});
|
|
await loading.present();
|
|
|
|
try {
|
|
const posts = await firstValueFrom(this.postsService.getAllPostsEndpoint());
|
|
this.posts.set(posts);
|
|
} catch {
|
|
const toast = await this.toastCtrl.create({
|
|
message: 'Impossible de charger les publications.',
|
|
duration: 2000,
|
|
color: 'danger'
|
|
});
|
|
await toast.present();
|
|
}
|
|
await loading.dismiss();
|
|
}
|
|
}
|