From 5234f9e940173059ebe6db7024ce6902684a991f Mon Sep 17 00:00:00 2001 From: dawidgil <83639710+dawidgil@users.noreply.github.com> Date: Tue, 2 Aug 2022 10:33:37 +0200 Subject: [PATCH] fix: show loader when getting list after notifications update --- src/app/layout/header/header.component.ts | 9 ------ .../my-enrolment-list.component.ts | 28 +++-------------- .../requested-enrolment-list.component.ts | 31 +------------------ .../message-subscription.service.ts | 11 ++++--- .../services/notification.service.spec.ts | 4 +-- .../shared/services/notification.service.ts | 4 +-- 6 files changed, 16 insertions(+), 71 deletions(-) diff --git a/src/app/layout/header/header.component.ts b/src/app/layout/header/header.component.ts index c1e802205..2b60ca729 100644 --- a/src/app/layout/header/header.component.ts +++ b/src/app/layout/header/header.component.ts @@ -1,10 +1,8 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { Event, NavigationEnd, Router } from '@angular/router'; import { Component, OnDestroy, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { DialogUserComponent } from './dialog-user/dialog-user.component'; -import { IamService } from '../../shared/services/iam.service'; import { NotificationService } from '../../shared/services/notification.service'; import { Subject } from 'rxjs'; import { filter, map, takeUntil } from 'rxjs/operators'; @@ -49,10 +47,8 @@ export class HeaderComponent implements OnInit, OnDestroy { ); private _subscription$ = new Subject(); - private _iamSubscriptionId: number; constructor( - private iamService: IamService, private router: Router, private notifService: NotificationService, public dialog: MatDialog, @@ -65,11 +61,6 @@ export class HeaderComponent implements OnInit, OnDestroy { async ngOnDestroy(): Promise { this._subscription$.next(); this._subscription$.complete(); - - // Unsubscribe to IAM Events - await this.iamService.messagingService.unsubscribeFrom( - this._iamSubscriptionId - ); } openDialogUser(): void { diff --git a/src/app/routes/enrolment/my-enrolment-list/my-enrolment-list.component.ts b/src/app/routes/enrolment/my-enrolment-list/my-enrolment-list.component.ts index 396a01a95..3ba54b21c 100644 --- a/src/app/routes/enrolment/my-enrolment-list/my-enrolment-list.component.ts +++ b/src/app/routes/enrolment/my-enrolment-list/my-enrolment-list.component.ts @@ -34,9 +34,9 @@ const TOASTR_HEADER = 'Enrolment'; templateUrl: './my-enrolment-list.component.html', styleUrls: ['./my-enrolment-list.component.scss'], }) -export class MyEnrolmentListComponent implements OnInit, OnDestroy { - @ViewChild('actions') actions; - @ViewChild('status') status; +export class MyEnrolmentListComponent implements OnInit { + @ViewChild('actions', { static: true }) actions; + @ViewChild('status', { static: true }) status; @Input() list: EnrolmentClaim[]; @ViewChild(MatSort) sort: MatSort; @@ -44,7 +44,6 @@ export class MyEnrolmentListComponent implements OnInit, OnDestroy { columns: ColumnDefinition[]; sorting = sortingEnrolmentData; - private _iamSubscriptionId: number; enrolmentType = EnrolmentListType.APPLICANT; enrolmentViewFilters: FilterStatus[] = [ FilterStatus.All, @@ -68,23 +67,10 @@ export class MyEnrolmentListComponent implements OnInit, OnDestroy { isAsset(element); } - async ngOnInit() { - // Subscribe to IAM events - this._iamSubscriptionId = - await this.iamService.messagingService.subscribeTo({ - messageHandler: this._handleMessage.bind(this), - }); - + ngOnInit() { this.defineColumns(); } - async ngOnDestroy(): Promise { - // Unsubscribe from IAM Events - await this.iamService.messagingService.unsubscribeFrom( - this._iamSubscriptionId - ); - } - isAccepted(element: EnrolmentClaim) { return element?.isAccepted; } @@ -164,12 +150,6 @@ export class MyEnrolmentListComponent implements OnInit, OnDestroy { this.refreshList.emit(); } - private async _handleMessage(message) { - if (message.issuedToken || message.isRejected) { - this.updateList(); - } - } - private defineColumns() { this.columns = [ { type: ColumnType.Date, field: 'requestDate', header: 'Request Date' }, diff --git a/src/app/routes/enrolment/requested-enrolment-list/requested-enrolment-list.component.ts b/src/app/routes/enrolment/requested-enrolment-list/requested-enrolment-list.component.ts index 9a2be7286..98d6b5814 100644 --- a/src/app/routes/enrolment/requested-enrolment-list/requested-enrolment-list.component.ts +++ b/src/app/routes/enrolment/requested-enrolment-list/requested-enrolment-list.component.ts @@ -25,7 +25,7 @@ import { EnrolmentListType } from '../enrolment-list/models/enrolment-list-type. templateUrl: './requested-enrolment-list.component.html', styleUrls: ['./requested-enrolment-list.component.scss'], }) -export class RequestedEnrolmentListComponent implements OnInit, OnDestroy { +export class RequestedEnrolmentListComponent { @ViewChild('actions', { static: true }) actions; @ViewChild('status', { static: true }) status; @Input() list: EnrolmentClaim[]; @@ -54,39 +54,10 @@ export class RequestedEnrolmentListComponent implements OnInit, OnDestroy { @ViewChild(MatSort) sort: MatSort; - private _iamSubscriptionId: number; - - constructor( - private loadingService: LoadingService, - private iamService: IamService, - private dialog: MatDialog - ) {} - - async ngOnInit() { - // Subscribe to IAM events - this._iamSubscriptionId = - await this.iamService.messagingService.subscribeTo({ - messageHandler: this._handleMessage.bind(this), - }); - } - - async ngOnDestroy(): Promise { - // Unsubscribe from IAM Events - await this.iamService.messagingService.unsubscribeFrom( - this._iamSubscriptionId - ); - } - isAccepted(element: EnrolmentClaim) { return element?.isAccepted; } - private async _handleMessage(message) { - if (!message.issuedToken) { - this.updateList(); - } - } - updateList() { this.refreshList.emit(); } diff --git a/src/app/shared/services/message-subscription/message-subscription.service.ts b/src/app/shared/services/message-subscription/message-subscription.service.ts index b476ddbc3..1216cae1d 100644 --- a/src/app/shared/services/message-subscription/message-subscription.service.ts +++ b/src/app/shared/services/message-subscription/message-subscription.service.ts @@ -25,14 +25,16 @@ export class MessageSubscriptionService implements OnDestroy { }); } - private handleMessage(message: any) { + private handleMessage(message: { + type: ClaimEventType & AssetHistoryEventType; + }) { if (message.type) { this.handleAssetEvents(message.type); this.handleClaimEvents(message.type); } } - private handleAssetEvents(type: string) { + private handleAssetEvents(type: AssetHistoryEventType) { switch (type) { case AssetHistoryEventType.ASSET_OFFERED: this.toastr.info('An asset is offered to you.', 'Asset Offered'); @@ -40,7 +42,7 @@ export class MessageSubscriptionService implements OnDestroy { break; case AssetHistoryEventType.ASSET_TRANSFERRED: this.toastr.success( - 'Your asset is successfully tranferred to a new owner.', + 'Your asset is successfully transferred to a new owner.', 'Asset Transferred' ); break; @@ -60,7 +62,7 @@ export class MessageSubscriptionService implements OnDestroy { } } - private handleClaimEvents(type: string) { + private handleClaimEvents(type: ClaimEventType) { switch (type) { case ClaimEventType.REQUEST_CREDENTIALS: this.notifService.updatePendingApprovalList(); @@ -78,6 +80,7 @@ export class MessageSubscriptionService implements OnDestroy { ); break; case ClaimEventType.REJECT_CREDENTIAL: + this.notifService.updatePendingApprovalList(); this.toastr.warning( 'Your enrolment request is rejected.', 'New Enrolment Request' diff --git a/src/app/shared/services/notification.service.spec.ts b/src/app/shared/services/notification.service.spec.ts index c69e52ba8..cae15acb1 100644 --- a/src/app/shared/services/notification.service.spec.ts +++ b/src/app/shared/services/notification.service.spec.ts @@ -81,7 +81,7 @@ describe('NotificationService', () => { const dispatchSpy = spyOn(store, 'dispatch'); service.updatePendingApprovalList(); expect(dispatchSpy).toHaveBeenCalledOnceWith( - RequestedEnrolmentsActions.updateEnrolmentRequests() + RequestedEnrolmentsActions.getEnrolmentRequests() ); }); @@ -89,7 +89,7 @@ describe('NotificationService', () => { const dispatchSpy = spyOn(store, 'dispatch'); service.updatePendingPublishList(); expect(dispatchSpy).toHaveBeenCalledOnceWith( - OwnedEnrolmentsActions.updateOwnedEnrolments() + OwnedEnrolmentsActions.getOwnedEnrolments() ); }); diff --git a/src/app/shared/services/notification.service.ts b/src/app/shared/services/notification.service.ts index fdfdca83f..e6e3a8f8d 100644 --- a/src/app/shared/services/notification.service.ts +++ b/src/app/shared/services/notification.service.ts @@ -41,11 +41,11 @@ export class NotificationService { } updatePendingApprovalList() { - this.store.dispatch(RequestedEnrolmentsActions.updateEnrolmentRequests()); + this.store.dispatch(RequestedEnrolmentsActions.getEnrolmentRequests()); } updatePendingPublishList() { - this.store.dispatch(OwnedEnrolmentsActions.updateOwnedEnrolments()); + this.store.dispatch(OwnedEnrolmentsActions.getOwnedEnrolments()); } increaseAssetsOfferedToMeCount() {