Skip to content

Commit

Permalink
fix: show loader when getting list after notifications update
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidgil committed Aug 2, 2022
1 parent 3ecb481 commit 5234f9e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 71 deletions.
9 changes: 0 additions & 9 deletions src/app/layout/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -65,11 +61,6 @@ export class HeaderComponent implements OnInit, OnDestroy {
async ngOnDestroy(): Promise<void> {
this._subscription$.next();
this._subscription$.complete();

// Unsubscribe to IAM Events
await this.iamService.messagingService.unsubscribeFrom(
this._iamSubscriptionId
);
}

openDialogUser(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ 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;
@Output() refreshList = new EventEmitter<void>();

columns: ColumnDefinition[];
sorting = sortingEnrolmentData;
private _iamSubscriptionId: number;
enrolmentType = EnrolmentListType.APPLICANT;
enrolmentViewFilters: FilterStatus[] = [
FilterStatus.All,
Expand 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<void> {
// Unsubscribe from IAM Events
await this.iamService.messagingService.unsubscribeFrom(
this._iamSubscriptionId
);
}

isAccepted(element: EnrolmentClaim) {
return element?.isAccepted;
}
Expand Down Expand Up @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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<void> {
// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ 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');
this.notifService.increaseAssetsOfferedToMeCount();
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;
Expand All @@ -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();
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/services/notification.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ describe('NotificationService', () => {
const dispatchSpy = spyOn(store, 'dispatch');
service.updatePendingApprovalList();
expect(dispatchSpy).toHaveBeenCalledOnceWith(
RequestedEnrolmentsActions.updateEnrolmentRequests()
RequestedEnrolmentsActions.getEnrolmentRequests()
);
});

it('should refresh owned enrolments list after publishing', () => {
const dispatchSpy = spyOn(store, 'dispatch');
service.updatePendingPublishList();
expect(dispatchSpy).toHaveBeenCalledOnceWith(
OwnedEnrolmentsActions.updateOwnedEnrolments()
OwnedEnrolmentsActions.getOwnedEnrolments()
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/services/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5234f9e

Please sign in to comment.