refactor(cover): add async cover notifications, for real time updates (#716)

This commit is contained in:
brios
2026-04-22 17:27:42 -04:00
committed by Zach Yale
parent 4bac913574
commit 7a88b12430
8 changed files with 102 additions and 57 deletions
@@ -1,5 +1,5 @@
import {Subject} from 'rxjs';
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
import {TranslocoService} from '@jsverse/transloco';
@@ -12,7 +12,6 @@ describe('LiveNotificationBoxComponent', () => {
let notifications$: Subject<LogNotification>;
let langChanges$: Subject<string>;
let component: LiveNotificationBoxComponent;
let fixture: ComponentFixture<LiveNotificationBoxComponent>;
beforeEach(() => {
notifications$ = new Subject<LogNotification>();
@@ -35,7 +34,7 @@ describe('LiveNotificationBoxComponent', () => {
],
});
fixture = TestBed.createComponent(LiveNotificationBoxComponent);
const fixture = TestBed.createComponent(LiveNotificationBoxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
@@ -1,4 +1,4 @@
import {Component, inject, OnDestroy} from '@angular/core';
import {ChangeDetectorRef, Component, inject, OnDestroy} from '@angular/core';
import {NotificationEventService} from '../../websocket/notification-event.service';
import {LogNotification} from '../../websocket/model/log-notification.model';
import {TranslocoService} from '@jsverse/transloco';
@@ -21,6 +21,7 @@ import {TagComponent} from '../tag/tag.component';
})
export class LiveNotificationBoxComponent implements OnDestroy {
private readonly t = inject(TranslocoService);
private readonly cdr = inject(ChangeDetectorRef);
private readonly destroy$ = new Subject<void>();
latestNotification: LogNotification = {message: this.t.translate('shared.liveNotification.defaultMessage')};
private hasReceivedNotification = false;
@@ -31,11 +32,13 @@ export class LiveNotificationBoxComponent implements OnDestroy {
this.notificationService.latestNotification$.pipe(takeUntil(this.destroy$)).subscribe(notification => {
this.hasReceivedNotification = true;
this.latestNotification = notification;
this.cdr.markForCheck();
});
this.t.langChanges$.pipe(takeUntil(this.destroy$)).subscribe(() => {
if (!this.hasReceivedNotification) {
this.latestNotification = {message: this.t.translate('shared.liveNotification.defaultMessage')};
}
this.cdr.markForCheck();
});
}