Added loading and refresh
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {Component, inject, OnInit} from '@angular/core';
|
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 {checkmarkCircleOutline, closeCircleOutline} from 'ionicons/icons';
|
||||||
import {addIcons} from "ionicons";
|
import {addIcons} from "ionicons";
|
||||||
import {PipeComponent} from "../pipe/pipe.component";
|
import {PipeComponent} from "../pipe/pipe.component";
|
||||||
@@ -25,6 +25,7 @@ export class FriendRequestComponent implements OnInit {
|
|||||||
private friendsService = inject(FriendsService);
|
private friendsService = inject(FriendsService);
|
||||||
private toastCtrl = inject(ToastController);
|
private toastCtrl = inject(ToastController);
|
||||||
private friendsState = inject(FriendsStateService);
|
private friendsState = inject(FriendsStateService);
|
||||||
|
private loadCtrl = inject(LoadingController)
|
||||||
|
|
||||||
friendsRequest = this.friendsState.requests;
|
friendsRequest = this.friendsState.requests;
|
||||||
|
|
||||||
@@ -32,7 +33,18 @@ export class FriendRequestComponent implements OnInit {
|
|||||||
await this.fetchFriendsRequest();
|
await this.fetchFriendsRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async ionViewWillEnter() {
|
||||||
|
await this.fetchFriendsRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async fetchFriendsRequest() {
|
async fetchFriendsRequest() {
|
||||||
|
const loading = await this.loadCtrl.create({
|
||||||
|
message: 'Chargement...',
|
||||||
|
spinner: 'lines-sharp-small'
|
||||||
|
});
|
||||||
|
await loading.present();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const requests = await firstValueFrom(this.friendsService.getAllFriendRequestsEndpoint());
|
const requests = await firstValueFrom(this.friendsService.getAllFriendRequestsEndpoint());
|
||||||
this.friendsState.setRequests(requests);
|
this.friendsState.setRequests(requests);
|
||||||
@@ -44,9 +56,17 @@ export class FriendRequestComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
await toast.present();
|
await toast.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await loading.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
async acceptRequest(request: GetFriendRequestDto) {
|
async acceptRequest(request: GetFriendRequestDto) {
|
||||||
|
const loading = await this.loadCtrl.create({
|
||||||
|
message: 'Chargement...',
|
||||||
|
spinner: 'lines-sharp-small'
|
||||||
|
});
|
||||||
|
await loading.present();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await firstValueFrom(this.friendsService.acceptFriendRequestEndpoint(request.userId));
|
await firstValueFrom(this.friendsService.acceptFriendRequestEndpoint(request.userId));
|
||||||
this.friendsState.acceptRequest(request);
|
this.friendsState.acceptRequest(request);
|
||||||
@@ -64,9 +84,16 @@ export class FriendRequestComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
await toast.present();
|
await toast.present();
|
||||||
}
|
}
|
||||||
|
await loading.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
async rejectRequest(id: number) {
|
async rejectRequest(id: number) {
|
||||||
|
const loading = await this.loadCtrl.create({
|
||||||
|
message: 'Chargement...',
|
||||||
|
spinner: 'lines-sharp-small'
|
||||||
|
});
|
||||||
|
await loading.present();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await firstValueFrom(this.friendsService.rejectFriendRequestEndpoint(id));
|
await firstValueFrom(this.friendsService.rejectFriendRequestEndpoint(id));
|
||||||
this.friendsState.removeRequest(id);
|
this.friendsState.removeRequest(id);
|
||||||
@@ -84,5 +111,6 @@ export class FriendRequestComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
await toast.present();
|
await toast.present();
|
||||||
}
|
}
|
||||||
|
await loading.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
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 {closeCircleOutline} from 'ionicons/icons';
|
||||||
import {addIcons} from "ionicons";
|
import {addIcons} from "ionicons";
|
||||||
import {FriendsService, GetUserDto, UsersService} from "../../services/api";
|
import {FriendsService, GetUserDto, UsersService} from "../../services/api";
|
||||||
@@ -23,6 +23,7 @@ export class FriendsListComponent implements OnInit {
|
|||||||
private usersService = inject(UsersService);
|
private usersService = inject(UsersService);
|
||||||
private toastCtrl = inject(ToastController);
|
private toastCtrl = inject(ToastController);
|
||||||
private friendsState = inject(FriendsStateService);
|
private friendsState = inject(FriendsStateService);
|
||||||
|
private loadCtrl = inject(LoadingController)
|
||||||
|
|
||||||
selectedFriend = signal<GetUserDto>(null);
|
selectedFriend = signal<GetUserDto>(null);
|
||||||
|
|
||||||
@@ -34,7 +35,17 @@ export class FriendsListComponent implements OnInit {
|
|||||||
await this.fetchFriends();
|
await this.fetchFriends();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async ionViewWillEnter() {
|
||||||
|
await this.fetchFriends();
|
||||||
|
}
|
||||||
|
|
||||||
async fetchFriends() {
|
async fetchFriends() {
|
||||||
|
const loading = await this.loadCtrl.create({
|
||||||
|
message: 'Chargement...',
|
||||||
|
spinner: 'lines-sharp-small'
|
||||||
|
});
|
||||||
|
await loading.present();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const friends = await firstValueFrom(this.friendsService.getAllFriendsEndpoint());
|
const friends = await firstValueFrom(this.friendsService.getAllFriendsEndpoint());
|
||||||
this.friendsState.setFriends(friends);
|
this.friendsState.setFriends(friends);
|
||||||
@@ -46,9 +57,16 @@ export class FriendsListComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
await toast.present();
|
await toast.present();
|
||||||
}
|
}
|
||||||
|
await loading.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteFriend(friendId: number) {
|
async deleteFriend(friendId: number) {
|
||||||
|
const loading = await this.loadCtrl.create({
|
||||||
|
message: 'Chargement...',
|
||||||
|
spinner: 'lines-sharp-small'
|
||||||
|
});
|
||||||
|
await loading.present();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await firstValueFrom(this.friendsService.deleteFriendEndpoint(friendId));
|
await firstValueFrom(this.friendsService.deleteFriendEndpoint(friendId));
|
||||||
const toast = await this.toastCtrl.create({
|
const toast = await this.toastCtrl.create({
|
||||||
@@ -66,9 +84,17 @@ export class FriendsListComponent implements OnInit {
|
|||||||
await toast.present();
|
await toast.present();
|
||||||
}
|
}
|
||||||
this.friendsState.removeFriend(friendId);
|
this.friendsState.removeFriend(friendId);
|
||||||
|
await loading.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setOpen(isOpen: boolean, userId: number) {
|
async setOpen(isOpen: boolean, userId: number) {
|
||||||
|
const loading = await this.loadCtrl.create({
|
||||||
|
message: 'Chargement...',
|
||||||
|
spinner: 'lines-sharp-small'
|
||||||
|
});
|
||||||
|
await loading.present();
|
||||||
|
|
||||||
|
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
try {
|
try {
|
||||||
const userInfo = await firstValueFrom(this.usersService.getUserEndpoint(userId));
|
const userInfo = await firstValueFrom(this.usersService.getUserEndpoint(userId));
|
||||||
@@ -83,5 +109,6 @@ export class FriendsListComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isModalOpen = isOpen;
|
this.isModalOpen = isOpen;
|
||||||
|
await loading.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,10 @@ export class RankingComponent implements OnInit {
|
|||||||
await this.fetchUsers();
|
await this.fetchUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async ionViewWillEnter() {
|
||||||
|
await this.fetchUsers();
|
||||||
|
}
|
||||||
|
|
||||||
async fetchUsers() {
|
async fetchUsers() {
|
||||||
const loading = await this.loadCtrl.create({
|
const loading = await this.loadCtrl.create({
|
||||||
message: 'Chargement...',
|
message: 'Chargement...',
|
||||||
|
|||||||
Reference in New Issue
Block a user