Show a persistent loader while a large library is being created (#2200)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -13,7 +13,10 @@ import {MetadataProgressService} from './shared/service/metadata-progress.servic
|
||||
import {BookdropFileNotification, BookdropFileService} from './features/bookdrop/service/bookdrop-file.service';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {DownloadProgressDialogComponent} from './shared/components/download-progress-dialog/download-progress-dialog.component';
|
||||
import {TaskService, TaskProgressPayload} from './features/settings/task-management/task.service';
|
||||
import {TaskProgressPayload, TaskService} from './features/settings/task-management/task.service';
|
||||
import {LibraryService} from './features/book/service/library.service';
|
||||
import {LibraryLoadingService} from './features/library-creator/library-loading.service';
|
||||
import {scan, withLatestFrom} from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -26,7 +29,9 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
loading = true;
|
||||
private subscriptions: Subscription[] = [];
|
||||
private subscriptionsInitialized = false; // Prevent multiple subscription setups
|
||||
private subscriptionsInitialized = false;
|
||||
|
||||
private appConfigService = inject(AppConfigService); // DO NOT REMOVE: Used to initialize app config on startup
|
||||
private authInit = inject(AuthInitializationService);
|
||||
private bookService = inject(BookService);
|
||||
private rxStompService = inject(RxStompService);
|
||||
@@ -34,7 +39,8 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
private metadataProgressService = inject(MetadataProgressService);
|
||||
private bookdropFileService = inject(BookdropFileService);
|
||||
private taskService = inject(TaskService);
|
||||
private appConfigService = inject(AppConfigService); // Keep it here to ensure the service is initialized
|
||||
private libraryService = inject(LibraryService);
|
||||
private libraryLoadingService = inject(LibraryLoadingService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.authInit.initialized$.subscribe(ready => {
|
||||
@@ -48,9 +54,25 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
private setupWebSocketSubscriptions(): void {
|
||||
this.subscriptions.push(
|
||||
this.rxStompService.watch('/user/queue/book-add').subscribe(msg =>
|
||||
this.bookService.handleNewlyCreatedBook(JSON.parse(msg.body))
|
||||
)
|
||||
this.rxStompService.watch('/user/queue/book-add').pipe(
|
||||
withLatestFrom(this.libraryService.largeLibraryLoading$),
|
||||
scan((acc, [msg, loadingState]) => {
|
||||
const book = JSON.parse(msg.body);
|
||||
if (loadingState.isLoading) {
|
||||
const newCount = acc.count + 1;
|
||||
this.libraryLoadingService.showBookLoadingProgress(book.metadata?.title || 'Unknown Book', newCount, loadingState.expectedCount);
|
||||
this.bookService.handleNewlyCreatedBook(book);
|
||||
if (newCount >= loadingState.expectedCount) {
|
||||
this.libraryService.setLargeLibraryLoading(false, 0);
|
||||
return {count: 0};
|
||||
}
|
||||
return {count: newCount};
|
||||
} else {
|
||||
this.bookService.handleNewlyCreatedBook(book);
|
||||
return {count: 0};
|
||||
}
|
||||
}, {count: 0})
|
||||
).subscribe()
|
||||
);
|
||||
this.subscriptions.push(
|
||||
this.rxStompService.watch('/user/queue/book-update').subscribe(msg =>
|
||||
@@ -104,5 +126,6 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.forEach(sub => sub.unsubscribe());
|
||||
this.libraryLoadingService.hide();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user