mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
remove notification duplicate
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService } from '../services/storage.service';
|
||||
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -8,9 +8,12 @@ export class NotificationHolderService {
|
||||
|
||||
notificationList = []
|
||||
|
||||
private _notificationList = []
|
||||
|
||||
|
||||
constructor(
|
||||
private storageService: StorageService,
|
||||
) {
|
||||
) {
|
||||
|
||||
try {
|
||||
this.restore()
|
||||
@@ -18,27 +21,34 @@ export class NotificationHolderService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
reverse() {
|
||||
this.notificationList = this._notificationList.reverse()
|
||||
}
|
||||
|
||||
restore() {
|
||||
this.storageService.get("Notifications").then((store) => {
|
||||
if(Array.isArray(store)) {
|
||||
this.notificationList = store
|
||||
this._notificationList = store
|
||||
this.reverse()
|
||||
}
|
||||
}).catch((error) => {})
|
||||
}
|
||||
|
||||
save() {
|
||||
this.storageService.store("Notifications", this.notificationList)
|
||||
this.storageService.store("Notifications", this._notificationList)
|
||||
}
|
||||
|
||||
addNotification(notification) {
|
||||
|
||||
const element = notification
|
||||
const i = this.notificationList.length + 1
|
||||
|
||||
const i = this._notificationList.length + 1
|
||||
|
||||
let notificationObject;
|
||||
if (element.notification) {
|
||||
|
||||
notificationObject = {
|
||||
id: notification?.id || uuidv4(),
|
||||
index: i,
|
||||
title: element.notification.title,
|
||||
Service: element.data.Service,
|
||||
@@ -57,6 +67,7 @@ export class NotificationHolderService {
|
||||
|
||||
} else if (element.data) {
|
||||
notificationObject = {
|
||||
id: notification?.id || uuidv4(),
|
||||
index: i,
|
||||
title: element.title,
|
||||
Service: element.data.Service,
|
||||
@@ -76,6 +87,7 @@ export class NotificationHolderService {
|
||||
} else {
|
||||
{
|
||||
notificationObject = {
|
||||
id: notification?.id || uuidv4(),
|
||||
FolderId: element.FolderId,
|
||||
IdObject: element.IdObject,
|
||||
Location: element.Location,
|
||||
@@ -94,8 +106,19 @@ export class NotificationHolderService {
|
||||
}
|
||||
}
|
||||
|
||||
this.notificationList.push(notificationObject)
|
||||
this.save()
|
||||
if(this.notificationExist(notificationObject)) {
|
||||
this._notificationList.push(notificationObject)
|
||||
this.reverse()
|
||||
this.save()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
notificationExist(notificationObject) {
|
||||
return this._notificationList.find(item => {
|
||||
return item.id === notificationObject.id;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -109,9 +132,11 @@ export class NotificationHolderService {
|
||||
}
|
||||
|
||||
removeNotification(notification) {
|
||||
this.notificationList = this.notificationList.filter( (e) => {
|
||||
this._notificationList = this._notificationList.filter( (e) => {
|
||||
return e.index != notification.index
|
||||
})
|
||||
|
||||
this.reverse()
|
||||
this.save()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user