Fixed refresh error with social page
This commit is contained in:
@@ -1,20 +1,45 @@
|
||||
import {Injectable, signal} from '@angular/core';
|
||||
import {GetFriendDto, GetFriendRequestDto} from "./api";
|
||||
import {inject, Injectable, signal} from '@angular/core';
|
||||
import {FriendsService, GetFriendDto, GetFriendRequestDto} from "./api";
|
||||
import {LoadingController, ToastController} from "@ionic/angular";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
export class FriendsStateService {
|
||||
private friendsService = inject(FriendsService);
|
||||
private toastCtrl = inject(ToastController);
|
||||
|
||||
friends = signal<GetFriendDto[]>([]);
|
||||
requests = signal<GetFriendRequestDto[]>([]);
|
||||
|
||||
setFriends(friends: GetFriendDto[]) {
|
||||
this.friends.set(friends);
|
||||
async fetchFriendsRequest() {
|
||||
try {
|
||||
const requests = await firstValueFrom(this.friendsService.getAllFriendRequestsEndpoint());
|
||||
this.requests.set(requests);
|
||||
} catch {
|
||||
const toast = await this.toastCtrl.create({
|
||||
message: 'Erreur lors du chargement des demandes d\'amis',
|
||||
duration: 2000,
|
||||
color: 'primary'
|
||||
});
|
||||
await toast.present();
|
||||
}
|
||||
}
|
||||
|
||||
setRequests(requests: GetFriendRequestDto[]) {
|
||||
this.requests.set(requests);
|
||||
async fetchFriends() {
|
||||
try {
|
||||
const friends = await firstValueFrom(this.friendsService.getAllFriendsEndpoint());
|
||||
this.friends.set(friends);
|
||||
} catch {
|
||||
const toast = await this.toastCtrl.create({
|
||||
message: 'Amis introuvables',
|
||||
duration: 2000,
|
||||
color: 'primary'
|
||||
});
|
||||
await toast.present();
|
||||
}
|
||||
}
|
||||
|
||||
acceptRequest(request: GetFriendRequestDto) {
|
||||
@@ -30,11 +55,11 @@ export class FriendsStateService {
|
||||
]);
|
||||
}
|
||||
|
||||
removeFriend(friendId: number) {
|
||||
this.friends.set(this.friends().filter(x => x.friendId !== friendId));
|
||||
}
|
||||
|
||||
removeRequest(friendId: number) {
|
||||
this.requests.set(this.requests().filter(x => x.userId !== friendId));
|
||||
}
|
||||
|
||||
removeFriend(friendId: number) {
|
||||
this.friends.set(this.friends().filter(x => x.friendId !== friendId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user