Started implementation of all posts
This commit is contained in:
@@ -1,13 +1,43 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {IonicModule} from "@ionic/angular";
|
||||
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
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user