refactor(ui): move large library processing screen to notifications (#1428)

Co-authored-by: Alex <25013571+alexhb1@users.noreply.github.com>
This commit is contained in:
brios
2026-05-22 15:57:07 +01:00
committed by GitHub
co-authored by Alex
parent 0e76b381aa
commit dbbc7c3878
20 changed files with 334 additions and 427 deletions
@@ -0,0 +1,65 @@
<ng-container *transloco="let t">
@if (progressService.state$ | async; as progress) {
@if (progress.active) {
<div class="rounded-lg border border-[var(--primary-color)] bg-[var(--card-background)] p-4">
<div class="mb-2 flex items-center justify-between gap-3">
<div class="flex min-w-0 items-center gap-2 text-[var(--primary-color)]">
<i class="pi pi-book" aria-hidden="true"></i>
<p class="m-0 text-sm font-semibold">{{ t('libraryCreator.loading.title') }}</p>
</div>
<p-tag
[value]="t(getStatusLabelKey(progress.status))"
[severity]="getTagSeverity(progress.status)">
</p-tag>
</div>
<div class="mb-2 break-words text-base text-zinc-200">
@if (progress.status === 'COMPLETED') {
{{ t('libraryCreator.loading.complete') }}
} @else if (progress.status === 'ERROR') {
{{ t('libraryCreator.creator.toast.createFailedSummary') }}
} @else {
{{ t('libraryCreator.loading.processing') }} <strong>{{ progress.currentBookTitle || progress.libraryName }}</strong>
}
</div>
<div class="mb-2 text-sm text-zinc-300 tabular-nums">
<span [innerHTML]="t('shared.metadataProgress.bookProgress', { current: getCurrentCount(progress), total: progress.expectedCount })"></span>
</div>
<p-progressBar
[style]="{ height: '15px' }"
[value]="getProgressPercent(progress)"
[showValue]="false">
</p-progressBar>
@if (progress.status !== 'IN_PROGRESS') {
<div class="mt-4 flex flex-wrap justify-end gap-2">
@if (progress.libraryId !== undefined) {
<button
pButton
type="button"
[label]="t('libraryCreator.loading.openLibrary')"
icon="pi pi-book"
severity="info"
size="small"
outlined
(click)="openLibrary(progress)">
</button>
}
<button
pButton
type="button"
[label]="t('shared.metadataProgress.dismissBtn')"
icon="pi pi-times"
severity="secondary"
size="small"
outlined
(click)="dismiss()">
</button>
</div>
}
</div>
}
}
</ng-container>
@@ -0,0 +1,65 @@
import {AsyncPipe} from '@angular/common';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {Router} from '@angular/router';
import {ButtonDirective} from 'primeng/button';
import {ProgressBar} from 'primeng/progressbar';
import {Tag} from 'primeng/tag';
import {TranslocoDirective} from '@jsverse/transloco';
import {LibraryImportProgressService, LibraryImportProgressState, LibraryImportProgressStatus} from '../../service/library-import-progress.service';
@Component({
selector: 'app-library-import-progress-widget',
templateUrl: './library-import-progress-widget-component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [AsyncPipe, ButtonDirective, ProgressBar, Tag, TranslocoDirective]
})
export class LibraryImportProgressWidgetComponent {
protected readonly progressService = inject(LibraryImportProgressService);
private readonly router = inject(Router);
getProgressPercent(state: LibraryImportProgressState): number {
if (state.expectedCount <= 0) return 0;
if (state.status === 'COMPLETED') return 100;
const percent = Math.round((state.processedCount / state.expectedCount) * 100);
return Math.min(100, Math.max(0, percent));
}
getCurrentCount(state: LibraryImportProgressState): number {
return Math.min(state.processedCount, state.expectedCount);
}
getStatusLabelKey(status: LibraryImportProgressStatus): string {
return {
IN_PROGRESS: 'shared.metadataProgress.statusInProgress',
COMPLETED: 'shared.metadataProgress.statusCompleted',
ERROR: 'shared.metadataProgress.statusError',
}[status];
}
getTagSeverity(status: LibraryImportProgressStatus): 'info' | 'success' | 'danger' {
switch (status) {
case 'COMPLETED':
return 'success';
case 'ERROR':
return 'danger';
case 'IN_PROGRESS':
default:
return 'info';
}
}
dismiss(): void {
this.progressService.clear();
}
openLibrary(state: LibraryImportProgressState): void {
if (state.libraryId === undefined) return;
this.router.navigate(['/library', state.libraryId, 'books']).then(navigated => {
if (navigated) {
this.dismiss();
}
});
}
}
@@ -3,6 +3,9 @@
@if (hasMetadataTasks$ | async) {
<app-metadata-progress-widget/>
}
@if (hasActiveLibraryImport$ | async) {
<app-library-import-progress-widget/>
}
@if (hasPendingBookdropFiles$ | async) {
<app-bookdrop-files-widget-component/>
}
@@ -6,6 +6,7 @@ import {BookdropFileService} from '../../../features/bookdrop/service/bookdrop-f
import {getTranslocoModule} from '../../../core/testing/transloco-testing';
import {MetadataBatchStatus} from '../../model/metadata-batch-progress.model';
import {MetadataProgressService} from '../../service/metadata-progress.service';
import {LibraryImportProgressService} from '../../service/library-import-progress.service';
import {UnifiedNotificationBoxComponent} from './unified-notification-popover-component';
describe('UnifiedNotificationBoxComponent', () => {
@@ -13,10 +14,12 @@ describe('UnifiedNotificationBoxComponent', () => {
let component: UnifiedNotificationBoxComponent;
let activeTasks$: BehaviorSubject<Record<string, unknown>>;
let hasPendingFiles$: BehaviorSubject<boolean>;
let hasActiveImport$: BehaviorSubject<boolean>;
beforeEach(async () => {
activeTasks$ = new BehaviorSubject<Record<string, unknown>>({});
hasPendingFiles$ = new BehaviorSubject(false);
hasActiveImport$ = new BehaviorSubject(false);
await TestBed.configureTestingModule({
imports: [UnifiedNotificationBoxComponent, getTranslocoModule()],
@@ -29,6 +32,10 @@ describe('UnifiedNotificationBoxComponent', () => {
provide: BookdropFileService,
useValue: {hasPendingFiles$},
},
{
provide: LibraryImportProgressService,
useValue: {hasActiveImport$},
},
],
}).compileComponents();
@@ -72,4 +79,15 @@ describe('UnifiedNotificationBoxComponent', () => {
hasPendingFiles$.next(true);
expect(hasPendingFiles).toBe(true);
});
it('forwards the active library import signal', () => {
let hasActiveImport: boolean | undefined;
component.hasActiveLibraryImport$.subscribe(value => {
hasActiveImport = value;
});
expect(hasActiveImport).toBe(false);
hasActiveImport$.next(true);
expect(hasActiveImport).toBe(true);
});
});
@@ -6,12 +6,15 @@ import {AsyncPipe} from '@angular/common';
import {BookdropFileService} from '../../../features/bookdrop/service/bookdrop-file.service';
import {BookdropFilesWidgetComponent} from '../../../features/bookdrop/component/bookdrop-files-widget/bookdrop-files-widget.component';
import {MetadataProgressWidgetComponent} from '../metadata-progress-widget/metadata-progress-widget-component';
import {LibraryImportProgressService} from '../../service/library-import-progress.service';
import {LibraryImportProgressWidgetComponent} from '../library-import-progress-widget/library-import-progress-widget-component';
@Component({
selector: 'app-unified-notification-popover-component',
imports: [
LiveNotificationBoxComponent,
MetadataProgressWidgetComponent,
LibraryImportProgressWidgetComponent,
AsyncPipe,
BookdropFilesWidgetComponent
],
@@ -22,10 +25,12 @@ import {MetadataProgressWidgetComponent} from '../metadata-progress-widget/metad
export class UnifiedNotificationBoxComponent {
metadataProgressService = inject(MetadataProgressService);
bookdropFileService = inject(BookdropFileService);
libraryImportProgressService = inject(LibraryImportProgressService);
hasMetadataTasks$ = this.metadataProgressService.activeTasks$.pipe(
map(tasks => Object.keys(tasks).length > 0)
);
hasPendingBookdropFiles$ = this.bookdropFileService.hasPendingFiles$;
hasActiveLibraryImport$ = this.libraryImportProgressService.hasActiveImport$;
}