Added loading and refresh

This commit is contained in:
2026-04-13 23:18:09 +01:00
parent 697f1e8490
commit ee09331baf
3 changed files with 61 additions and 2 deletions
@@ -1,5 +1,5 @@
import {Component, inject, OnInit} from '@angular/core';
import {IonicModule, ToastController} from "@ionic/angular";
import {IonicModule, LoadingController, ToastController} from "@ionic/angular";
import {checkmarkCircleOutline, closeCircleOutline} from 'ionicons/icons';
import {addIcons} from "ionicons";
import {PipeComponent} from "../pipe/pipe.component";
@@ -25,6 +25,7 @@ export class FriendRequestComponent implements OnInit {
private friendsService = inject(FriendsService);
private toastCtrl = inject(ToastController);
private friendsState = inject(FriendsStateService);
private loadCtrl = inject(LoadingController)
friendsRequest = this.friendsState.requests;
@@ -32,7 +33,18 @@ export class FriendRequestComponent implements OnInit {
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);
@@ -44,9 +56,17 @@ export class FriendRequestComponent implements OnInit {
});
await toast.present();
}
await loading.dismiss();
}
async acceptRequest(request: GetFriendRequestDto) {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
await firstValueFrom(this.friendsService.acceptFriendRequestEndpoint(request.userId));
this.friendsState.acceptRequest(request);
@@ -64,9 +84,16 @@ export class FriendRequestComponent implements OnInit {
});
await toast.present();
}
await loading.dismiss();
}
async rejectRequest(id: number) {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
await firstValueFrom(this.friendsService.rejectFriendRequestEndpoint(id));
this.friendsState.removeRequest(id);
@@ -84,5 +111,6 @@ export class FriendRequestComponent implements OnInit {
});
await toast.present();
}
await loading.dismiss();
}
}
@@ -1,5 +1,5 @@
import {Component, inject, OnInit, signal} from '@angular/core';
import {IonicModule, ToastController} from "@ionic/angular";
import {IonicModule, LoadingController, ToastController} from "@ionic/angular";
import {closeCircleOutline} from 'ionicons/icons';
import {addIcons} from "ionicons";
import {FriendsService, GetUserDto, UsersService} from "../../services/api";
@@ -23,6 +23,7 @@ export class FriendsListComponent implements OnInit {
private usersService = inject(UsersService);
private toastCtrl = inject(ToastController);
private friendsState = inject(FriendsStateService);
private loadCtrl = inject(LoadingController)
selectedFriend = signal<GetUserDto>(null);
@@ -34,7 +35,17 @@ export class FriendsListComponent implements OnInit {
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);
@@ -46,9 +57,16 @@ export class FriendsListComponent implements OnInit {
});
await toast.present();
}
await loading.dismiss();
}
async deleteFriend(friendId: number) {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
await firstValueFrom(this.friendsService.deleteFriendEndpoint(friendId));
const toast = await this.toastCtrl.create({
@@ -66,9 +84,17 @@ export class FriendsListComponent implements OnInit {
await toast.present();
}
this.friendsState.removeFriend(friendId);
await loading.dismiss();
}
async setOpen(isOpen: boolean, userId: number) {
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
if (isOpen) {
try {
const userInfo = await firstValueFrom(this.usersService.getUserEndpoint(userId));
@@ -83,5 +109,6 @@ export class FriendsListComponent implements OnInit {
}
}
this.isModalOpen = isOpen;
await loading.dismiss();
}
}
@@ -22,6 +22,10 @@ export class RankingComponent implements OnInit {
await this.fetchUsers();
}
async ionViewWillEnter() {
await this.fetchUsers();
}
async fetchUsers() {
const loading = await this.loadCtrl.create({
message: 'Chargement...',