refactor(ui): convert bookdrop progress to signals (#1626)

This commit is contained in:
Alex
2026-06-03 14:30:09 +01:00
committed by GitHub
parent 9d30913b3a
commit 9de1c9d55a
9 changed files with 106 additions and 91 deletions
@@ -14,12 +14,12 @@ describe('UnifiedNotificationBoxComponent', () => {
let fixture: ComponentFixture<UnifiedNotificationBoxComponent>;
let component: UnifiedNotificationBoxComponent;
let activeTasks$: BehaviorSubject<Record<string, unknown>>;
let hasPendingFiles$: BehaviorSubject<boolean>;
let hasPendingFiles: WritableSignal<boolean>;
let hasActiveImport: WritableSignal<boolean>;
beforeEach(async () => {
activeTasks$ = new BehaviorSubject<Record<string, unknown>>({});
hasPendingFiles$ = new BehaviorSubject(false);
hasPendingFiles = signal(false);
hasActiveImport = signal(false);
await TestBed.configureTestingModule({
@@ -31,7 +31,7 @@ describe('UnifiedNotificationBoxComponent', () => {
},
{
provide: BookdropFileService,
useValue: {hasPendingFiles$},
useValue: {hasPendingFiles},
},
{
provide: LibraryImportProgressService,
@@ -71,7 +71,7 @@ describe('UnifiedNotificationBoxComponent', () => {
const popover = component as unknown as {hasPendingBookdropFiles: Signal<boolean>};
expect(popover.hasPendingBookdropFiles()).toBe(false);
hasPendingFiles$.next(true);
hasPendingFiles.set(true);
expect(popover.hasPendingBookdropFiles()).toBe(true);
});
@@ -28,6 +28,6 @@ export class UnifiedNotificationBoxComponent {
private readonly activeMetadataTasks = toSignal(this.metadataProgressService.activeTasks$, {initialValue: {}});
protected readonly hasMetadataTasks = computed(() => Object.keys(this.activeMetadataTasks()).length > 0);
protected readonly hasPendingBookdropFiles = toSignal(this.bookdropFileService.hasPendingFiles$, {initialValue: false});
protected readonly hasPendingBookdropFiles = this.bookdropFileService.hasPendingFiles;
protected readonly hasActiveLibraryImport = this.libraryImportProgressService.hasActiveImport;
}
@@ -42,7 +42,7 @@ describe('AppSidebarComponent', () => {
let versionInfo: BehaviorSubject<AppVersion>;
let activeTasks$: BehaviorSubject<Record<string, MetadataBatchProgressNotification>>;
let progressUpdates$: BehaviorSubject<MetadataBatchProgressNotification>;
let hasPendingFiles$: BehaviorSubject<boolean>;
let hasPendingFiles: WritableSignal<boolean>;
let hasActiveImport: WritableSignal<boolean>;
const sidebarCollapsed = signal(false);
const isDesktop = signal(true);
@@ -71,7 +71,7 @@ describe('AppSidebarComponent', () => {
status: MetadataBatchStatus.COMPLETED,
review: false,
});
hasPendingFiles$ = new BehaviorSubject(false);
hasPendingFiles = signal(false);
hasActiveImport = signal(false);
TestBed.configureTestingModule({
@@ -101,7 +101,7 @@ describe('AppSidebarComponent', () => {
{ provide: BookDialogHelperService, useValue: { openShelfCreatorDialog: vi.fn(() => Promise.resolve(null)) } },
{ provide: AuthService, useValue: { logout: vi.fn() } },
{ provide: MetadataProgressService, useValue: { activeTasks$, progressUpdates$ } },
{ provide: BookdropFileService, useValue: { hasPendingFiles$ } },
{ provide: BookdropFileService, useValue: { hasPendingFiles } },
{ provide: LibraryImportProgressService, useValue: { hasActiveImport } },
{ provide: VersionService, useValue: { getVersion: vi.fn(() => versionInfo) } },
{ provide: LayoutService, useValue: layoutService },
@@ -288,7 +288,7 @@ describe('AppSidebarComponent', () => {
review: true,
},
});
hasPendingFiles$.next(true);
hasPendingFiles.set(true);
hasActiveImport.set(true);
expect(sidebar.completedTaskCount()).toBe(4);
@@ -235,7 +235,7 @@ export class AppSidebarComponent {
private readonly progressHighlight = computed(() =>
this.latestProgress()?.status === MetadataBatchStatus.IN_PROGRESS
);
private readonly hasPendingBookdropFiles = toSignal(this.bookdropFileService.hasPendingFiles$, { initialValue: false });
private readonly hasPendingBookdropFiles = this.bookdropFileService.hasPendingFiles;
private readonly hasActiveLibraryImport = this.libraryImportProgressService.hasActiveImport;
protected readonly completedTaskCount = computed(() => {
const metadataTaskCount = Object.keys(this.activeMetadataTasks()).length;