Started implementation of all posts

This commit is contained in:
2026-05-14 11:19:48 +01:00
parent e483bc4e57
commit 6a1ed5abeb
9 changed files with 87 additions and 76 deletions
+42
View File
@@ -0,0 +1,42 @@
import {Component, inject, input, OnInit, signal} from '@angular/core';
import {FriendsService, GetFriendDto, GetPostDto} from "../../services/api";
import {firstValueFrom} from "rxjs";
import {LoadingController, ToastController} from "@ionic/angular";
@Component({
selector: 'app-post',
templateUrl: './post.component.html',
styleUrls: ['./post.component.scss'],
})
export class PostComponent implements OnInit {
private friendsService = inject(FriendsService);
private loadCtrl = inject(LoadingController);
private toastCtrl = inject(ToastController);
friends = signal<GetFriendDto[]>([]);
posts = input.required<GetPostDto[]>();
postsFriends = signal<GetPostDto[]>([]);
async ngOnInit() {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
const friends = await firstValueFrom(this.friendsService.getAllFriendsEndpoint());
this.friends.set(friends);
this.postsFriends.set(this.posts().filter(post => this.friends().map(x => x.friendId).includes(post.userId)));
} catch {
const toast = await this.toastCtrl.create({
message: 'Erreur lors du chargement des amis.',
duration: 2000,
color: 'danger'
});
await toast.present();
}
await loading.dismiss();
}
}