From 917a0dcc9fcf238e00f6527d03a1fa9a0ba5b412 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Mon, 13 Apr 2026 23:18:09 +0100 Subject: [PATCH] Added loading and refresh --- .../friend-request.component.ts | 30 ++++++++++++++++++- .../friends/friends-list.component.ts | 29 +++++++++++++++++- src/app/pages/ranking/ranking.component.ts | 4 +++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/app/components/friend-request/friend-request.component.ts b/src/app/components/friend-request/friend-request.component.ts index 6ffebb1..fa7ff1f 100644 --- a/src/app/components/friend-request/friend-request.component.ts +++ b/src/app/components/friend-request/friend-request.component.ts @@ -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(); } } diff --git a/src/app/components/friends/friends-list.component.ts b/src/app/components/friends/friends-list.component.ts index b83b387..befc069 100644 --- a/src/app/components/friends/friends-list.component.ts +++ b/src/app/components/friends/friends-list.component.ts @@ -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(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(); } } \ No newline at end of file diff --git a/src/app/pages/ranking/ranking.component.ts b/src/app/pages/ranking/ranking.component.ts index b9575b5..fe60906 100644 --- a/src/app/pages/ranking/ranking.component.ts +++ b/src/app/pages/ranking/ranking.component.ts @@ -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...',