-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat_api(fe): added alert notifications
- Loading branch information
1 parent
d64f19d
commit 3977c26
Showing
7 changed files
with
99 additions
and
47 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
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
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
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
8 changes: 4 additions & 4 deletions
8
...ices/webSocket/web-socket.service.spec.ts → ...notification/notification.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
48 changes: 48 additions & 0 deletions
48
frontend/src/app/services/notification/notification.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,48 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { Item } from '../../shared/shared.module'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class NotificationService { | ||
private lastId = 0; | ||
private notificationsSubject = new BehaviorSubject<Item[]>([]); | ||
notifications$ = this.notificationsSubject.asObservable(); | ||
|
||
constructor() {} | ||
|
||
/** | ||
* Adds a new notification with the specified message. | ||
* | ||
* This method creates a new notification object with a unique ID and the provided message. | ||
* It then updates the current notifications list by adding the new notification and | ||
* emits the updated list using the `notificationsSubject`. | ||
* | ||
* @param message - The message to be included in the new notification. | ||
*/ | ||
addNotification(message: string): void { | ||
const newNotification: Item = { | ||
id: ++this.lastId, | ||
name: message | ||
}; | ||
|
||
const currentNotifications = this.notificationsSubject.value; | ||
this.notificationsSubject.next([...currentNotifications, newNotification]); | ||
} | ||
|
||
/** | ||
* Removes a notification with the specified ID. | ||
* | ||
* This method filters out the notification with the given ID from the current notifications list | ||
* and emits the updated list using the `notificationsSubject`. | ||
* | ||
* @param id - The ID of the notification to be removed. | ||
*/ | ||
removeNotification(id: number): void { | ||
const updatedNotifications = this.notificationsSubject.value.filter( | ||
(notification) => notification.id !== id | ||
); | ||
this.notificationsSubject.next(updatedNotifications); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.