Fixed refresh error with social page

This commit is contained in:
2026-04-14 13:46:17 +01:00
parent 4df957ddfb
commit f13541ccab
4 changed files with 69 additions and 76 deletions
@@ -1,4 +1,4 @@
import {Component, inject, OnInit} from '@angular/core';
import {Component, inject} from '@angular/core';
import {IonicModule, LoadingController, ToastController} from "@ionic/angular";
import {checkmarkCircleOutline, closeCircleOutline} from 'ionicons/icons';
import {addIcons} from "ionicons";
@@ -21,7 +21,7 @@ addIcons({
PipeComponent
]
})
export class FriendRequestComponent implements OnInit {
export class FriendRequestComponent {
private friendsService = inject(FriendsService);
private toastCtrl = inject(ToastController);
private friendsState = inject(FriendsStateService);
@@ -29,37 +29,6 @@ export class FriendRequestComponent implements OnInit {
friendsRequest = this.friendsState.requests;
async ngOnInit() {
await this.fetchFriendsRequest();
}
async ionViewWillEnter() {
await this.fetchFriendsRequest();
}
async fetchFriendsRequest() {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
const requests = await firstValueFrom(this.friendsService.getAllFriendRequestsEndpoint());
this.friendsState.setRequests(requests);
} catch (e) {
const toast = await this.toastCtrl.create({
message: 'Erreur lors du chargement des demandes d\'amis',
duration: 2000,
color: 'primary'
});
await toast.present();
}
await loading.dismiss();
}
async acceptRequest(request: GetFriendRequestDto) {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
@@ -18,7 +18,7 @@ addIcons({
IonicModule
]
})
export class FriendsListComponent implements OnInit {
export class FriendsListComponent {
private friendsService = inject(FriendsService);
private usersService = inject(UsersService);
private toastCtrl = inject(ToastController);
@@ -31,35 +31,6 @@ export class FriendsListComponent implements OnInit {
friends = this.friendsState.friends;
async ngOnInit() {
await this.fetchFriends();
}
async ionViewWillEnter() {
await this.fetchFriends();
}
async fetchFriends() {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
const friends = await firstValueFrom(this.friendsService.getAllFriendsEndpoint());
this.friendsState.setFriends(friends);
} catch (e) {
const toast = await this.toastCtrl.create({
message: 'Amis introuvables',
duration: 2000,
color: 'primary'
});
await toast.present();
}
await loading.dismiss();
}
async deleteFriend(friendId: number) {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
+31 -3
View File
@@ -1,11 +1,12 @@
import {Component} from '@angular/core';
import {Component, inject, OnInit} from '@angular/core';
import {TitlePartComponent} from "../../components/title-part/title-part.component";
import {IonicModule} from "@ionic/angular";
import {IonicModule, LoadingController} from "@ionic/angular";
import {FriendRequestComponent} from "../../components/friend-request/friend-request.component";
import {FriendsListComponent} from "../../components/friends/friends-list.component";
import {addIcons} from "ionicons";
import {addCircleOutline} from 'ionicons/icons';
import {SearchFriendComponent} from "../../components/search-friend/search-friend.component";
import {FriendsStateService} from "../../services/friends-state";
addIcons({
"send": addCircleOutline
@@ -23,6 +24,33 @@ addIcons({
SearchFriendComponent
]
})
export class SocialComponent {
export class SocialComponent implements OnInit {
private friendsState = inject(FriendsStateService);
private loadCtrl = inject(LoadingController);
async ngOnInit() {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
await this.friendsState.fetchFriendsRequest();
await this.friendsState.fetchFriends();
await loading.dismiss();
}
async ionViewWillEnter() {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
await this.friendsState.fetchFriendsRequest();
await this.friendsState.fetchFriends();
await loading.dismiss();
}
}
+35 -10
View File
@@ -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));
}
}