Added loading and refresh
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user