This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(front-end): Receive notifications in real time
- Loading branch information
1 parent
7658688
commit 334827f
Showing
4 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 18 additions & 4 deletions
22
Kaizen/ClientApp/src/app/shared/components/notifications/notifications.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Kaizen/ClientApp/src/app/shared/services/notifications-signalr.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NotificationsSignalrService } from './notifications-signalr.service'; | ||
|
||
describe('NotificationsSignalrService', () => { | ||
let service: NotificationsSignalrService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ HttpClientTestingModule ] | ||
}); | ||
service = TestBed.inject(NotificationsSignalrService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
Kaizen/ClientApp/src/app/shared/services/notifications-signalr.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Injectable, EventEmitter } from '@angular/core'; | ||
import { AuthenticationService } from '@core/authentication/authentication.service'; | ||
import { BaseSignalrService } from '@core/services/base-signalr.service'; | ||
import { NotificationItem } from '@shared/models/notification-item'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NotificationsSignalrService extends BaseSignalrService { | ||
onNewNotification$: EventEmitter<NotificationItem> = new EventEmitter<NotificationItem>(); | ||
|
||
constructor(private authService: AuthenticationService) { | ||
super(); | ||
this.startConnection(); | ||
} | ||
|
||
public startConnection(): void { | ||
super.buildConnection('/NotificationHub', this.authService.getToken()); | ||
super.startConnection(); | ||
this.addOnNewNotification(); | ||
} | ||
|
||
public addOnNewNotification(): void { | ||
this.hubConnection.on('OnNewNotification', (notification: NotificationItem) => { | ||
this.onNewNotification$.emit(notification); | ||
}); | ||
} | ||
} |