Files
grimmory/booklore-ui/src/app/book/service/event.service.ts
T
2024-12-27 11:14:31 -07:00

39 lines
1.1 KiB
TypeScript

import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {LogNotification} from '../model/log-notification.model';
@Injectable({
providedIn: 'root',
})
export class EventService {
private latestEventSubject = new BehaviorSubject<LogNotification>({message: 'No recent notifications...'});
latestEvent$ = this.latestEventSubject.asObservable();
private eventHighlightSubject = new BehaviorSubject<boolean>(false);
eventHighlight$ = this.eventHighlightSubject.asObservable();
private eventTimeout: any;
constructor() {
}
handleIncomingLog(logNotification: LogNotification): void {
this.latestEventSubject.next(logNotification);
this.eventHighlightSubject.next(true);
if (this.eventTimeout) {
clearTimeout(this.eventTimeout);
}
this.eventTimeout = setTimeout(() => {
this.eventHighlightSubject.next(false);
}, 2500);
setTimeout(() => {
if (!this.eventHighlightSubject.value) {
this.latestEventSubject.next({message: 'No recent notifications...'});
}
}, 7500);
}
}